#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
char src[5000 + 5];
char dest[5000 + 5];
int abs(int a) {
return a < 0 ? -a : a;
}
void solve() {
int i = -1;
int j = -1;
int ans = 0;
while (1) {
while (1) {
++i;
if (src[i] == '\0' || src[i] == '+') break;
}
while (1) {
++j;
if (dest[j] == '\0' || dest[j] == '+') break;
}
if (src[i] != dest[j]) {
ans = -1;
break;
}
ans = ans + abs(j - i);
if (src[i] == '\0') break;
}
printf("%d\n", ans);
}
int main() {
scanf("%s", src);
scanf("%s", dest);
solve();
return 0;
}