#include <bits/stdc++.h>
int main() {
  char a[1002], b[1002];
  int a1[26], b1[26];
  int i, j;
  int sum;
  while (scanf("%s", a) != EOF) {
    sum = 0;
    for (i = 0; i < 26; i++) {
      a1[i] = 0;
      b1[i] = 0;
    }
    scanf("%s", b);
    for (i = 0; i < strlen(a); i++) {
      a1[a[i] - 'a']++;
    }
    for (i = 0; i < strlen(b); i++) b1[b[i] - 'a']++;
    for (i = 0; i < 26; i++) {
      if (a1[i] == 0 && b1[i] != 0) {
        sum = -1;
        break;
      } else if (a1[i] < b1[i])
        sum += a1[i];
      else
        sum += b1[i];
    }
    printf("%d\n", sum);
  }
}
