#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[1005], b[1005];
  int i, len1, len2, x1 = 0, x2 = 0, ans = 0, max, j;
  cin >> a >> b;
  len1 = strlen(a);
  len2 = strlen(b);
  max = (len1 > len2) ? len1 : len2;
  for (i = 0; i < len2; i++) {
    if (b[i] != '*') {
      for (j = 0; j < max; j++) {
        if (j < len1) {
          if (a[j] == b[i]) {
            x1++;
            a[j] = '*';
          }
        }
        if (j < len2) {
          if (b[j] == b[i]) {
            x2++;
            if (j != i) b[j] = '*';
          }
        }
      }
      b[i] = '*';
      if (x1 == 0 && x2 != 0) {
        cout << -1;
        return 0;
      }
      if (x1 == x2 || x1 < x2) ans += x1;
      if (x1 > x2) ans += x2;
      x1 = 0;
      x2 = 0;
    }
  }
  cout << ans;
  return 0;
}
