#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    int l1 = s1.size();
    int l2 = s2.size();
    int arr1[125] = {0};
    int arr2[125] = {0};
    for (int i = 0; i < l1; i++) {
      arr1[(int)s1[i]]++;
    }
    for (int i = 0; i < l2; i++) {
      arr2[(int)s2[i]]++;
    }
    int res = 0;
    int cnt = 0;
    for (int i = 97; i <= 122; i++) {
      if (arr1[i] != 0 && arr2[i] != 0) {
        res += min(arr1[i], arr2[i]);
        cnt++;
      }
    }
    int p = 0;
    for (int i = 97; i <= 122; i++) {
      if (arr2[i] != 0) p++;
    }
    if (res == 0 || cnt != p)
      printf("-1\n");
    else
      printf("%d\n", res);
  }
  return 0;
}
