#include <bits/stdc++.h>
using namespace std;
int min(int a, int b) { return a > b ? b : a; }
int main() {
  char have[1005], wanted[1005];
  int i, j, a[26], b[26], ans;
  while (~scanf("%s%s", have, wanted)) {
    ans = 0;
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    int l1 = strlen(have);
    int l2 = strlen(wanted);
    for (i = 0; i < l1; i++) {
      a[have[i] - 'a']++;
    }
    for (i = 0; i < l2; i++) {
      b[wanted[i] - 'a']++;
    }
    for (i = 0; i < 26; i++) {
      ans += min(a[i], b[i]);
      if (a[i] == 0 && b[i] != 0) {
        ans = 0;
        break;
      }
    }
    if (ans)
      printf("%d\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
