#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  cin >> s1;
  cin >> s2;
  int arr[27] = {};
  int a[27] = {};
  string s = "";
  for (int i = 0; i < s1.length(); i++) {
    arr[int(s1[i]) - 97]++;
  }
  int count1 = 0;
  for (int i = 0; i < s2.length(); i++) {
    if (arr[int(s2[i]) - 97] == 0) {
      cout << -1;
      count1++;
      break;
    } else {
      if (a[int(s2[i]) - 97] == 0) {
        s += s2[i];
      }
      a[int(s2[i]) - 97]++;
    }
  }
  long long int sum = 0;
  if (count1 == 0) {
    for (int i = 0; i < s.length(); i++) {
      if (a[int(s[i]) - 97] <= arr[int(s[i]) - 97]) {
        sum += a[int(s[i]) - 97];
      } else {
        sum += arr[int(s[i]) - 97];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
