#include <bits/stdc++.h>
using namespace std;
char str1[2000], str2[2000];
int a[200], b[200];
int main() {
  while (scanf("%s", str1) != EOF) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    scanf("%s", str2);
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int p;
    for (p = 0; p < len1; p++) a[str1[p]]++;
    for (int i = 0; i < len2; i++) b[str2[i]]++;
    bool flag = 0;
    for (int i = 97; i <= 122; i++) {
      if (a[i] == 0 && b[i] != 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      printf("-1\n");
      continue;
    }
    int sum = 0;
    for (int i = 97; i <= 122; i++) sum += min(a[i], b[i]);
    printf("%d\n", sum);
  }
  return 0;
}
