#include<stdio.h>
#include<string.h>
int main()
{
char a[5000], b[5000], temp;
int len, i, t;
while (scanf("%s%s", a, b) != EOF)
{
int c = 0, d = 0, num = 0;
len = strlen(a);
for (i = 0; i < len; i++)
{
if (a[i] == '+')
c++;
if (b[i] == '+')
d++;
}
if (c != d)
{
printf("-1\n");
continue;
}
i = 0;
while (i < len)
{
if (a[i] == b[i])
{
i++;
continue;
}
else
{
t = i;
temp = a[i];
while (b[i] != a[t])
i++;
while (i > t)
{
b[i] = b[i-1];
i--;
num++;
}
b[t] = temp;
i = t + 1;
}
}
printf("%d\n",num);
}
return 0;
}