#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char with[1005], make[1005];
  int count1[26], count2[26], ans = 0;
  bool flag = false;
  scanf("%s", with);
  memset(count1, 0, sizeof(count1));
  memset(count2, 0, sizeof(count2));
  for (int i = 0; with[i]; i++) {
    count1[with[i] - 'a']++;
  }
  int m;
  scanf("%s", make);
  for (int j = 0; make[j]; j++) {
    count2[make[j] - 'a']++;
  }
  for (int i = 0; i <= 25; i++) {
    if (count1[i] >= count2[i])
      ans += count2[i];
    else if (count1[i] < count2[i] && count1[i] > 0)
      ans += count1[i];
    else
      flag = true;
  }
  if (flag) {
    cout << "-1" << endl;
  } else
    cout << ans << endl;
  return 0;
}
