//CodeForces 408B
1 #include "iostream"
2 #include "cstdio"
3 #include "cstring"
4 #include "algorithm"
5 using namespace std;
6 int n1[30], n2[30];
7 char s1[1010], s2[1010];
8 int len1, len2;
9
10 int main()
11 {
12 int i, j;
13 scanf("%s%s", s1, s2);
14 len1 = strlen(s1);
15 len2 = strlen(s2);
16 for(i = 0; i < len1; ++i) {
17 ++n1[s1[i] - 'a'];
18 }
19 for(i = 0; i < len2; ++i) {
20 ++n2[s2[i] - 'a'];
21 }
22 bool done = 1;
23 int res = 0;
24 for(i = 0; i < 26; ++i) {
25 if(!n1[i] && n2[i]){
26 done = 0;
27 break;
28 }
29 res += min(n1[i], n2[i]);
30 }
31 if(!done)
32 printf("-1
");
33 else
34 printf("%d
", res);
35 }