#include <bits/stdc++.h>
int main() {
  int len1, len2;
  char a[1001], b[1001];
  while (scanf("%s", a) != EOF) {
    getchar();
    scanf("%s", b);
    len1 = strlen(a);
    len2 = strlen(b);
    int s1[27], s2[27];
    memset(s1, 0, sizeof(s1));
    memset(s2, 0, sizeof(s2));
    int i;
    for (i = 0; i < len1; i++) {
      s1[a[i] - 'a']++;
    }
    for (i = 0; i < len2; i++) {
      s2[b[i] - 'a']++;
    }
    int sum = 0;
    for (i = 0; i <= 26; i++) {
      if (s2[i] > s1[i])
        sum += s1[i];
      else
        sum += s2[i];
      if (s2[i] > 0 && s1[i] == 0) {
        sum = -1;
        break;
      }
    }
    printf("%d\n", sum);
    getchar();
  }
  return 0;
}
