#include <bits/stdc++.h>
using namespace std;
int a[30], b[30];
char sa[1005], sb[1005];
int main() {
  int i, j, k;
  while (cin >> sa >> sb) {
    int la = strlen(sa);
    int lb = strlen(sb);
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (i = 0; i < la; i++) {
      a[sa[i] - 'a']++;
    }
    for (i = 0; i < lb; i++) {
      b[sb[i] - 'a']++;
    }
    int ans = 0;
    for (i = 0; i <= 'z' - 'a'; i++) {
      if (a[i] == 0 && b[i] != 0) {
        ans = -1;
        break;
      }
      if (a[i] <= b[i])
        ans += a[i];
      else
        ans += b[i];
    }
    cout << ans << endl;
  }
  return 0;
}
