#include <bits/stdc++.h>
char a[1010], b[1010];
int num1[30], num2[30];
int main() {
  int i;
  int L1, L2;
  int sum;
  while (~scanf("%s%s", a, b)) {
    L1 = strlen(a);
    L2 = strlen(b);
    sum = 0;
    memset(num1, 0, sizeof(num1));
    memset(num2, 0, sizeof(num2));
    for (i = 0; i < L1; i++) {
      num1[a[i] - 'a']++;
    }
    for (i = 0; i < L2; i++) {
      num2[b[i] - 'a']++;
    }
    for (i = 0; i < 26; i++) {
      if (num1[i] >= num2[i]) {
        sum += num2[i];
      } else if (num1[i] == 0) {
        sum = -1;
        break;
      } else {
        sum += num1[i];
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
