#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  string m;
  cin >> n;
  cin >> m;
  int arr[26];
  int brr[26];
  for (int i = 0; i < 26; i++) {
    arr[i] = 0;
  }
  for (int i = 0; i < 26; i++) {
    brr[i] = 0;
  }
  for (int i = 0; i < n.length(); i++) {
    arr[(int)n[i] - 97]++;
  }
  for (int i = 0; i < m.length(); i++) {
    brr[(int)m[i] - 97]++;
  }
  int ans = 0;
  int flag = 0;
  for (int i = 0; i < 26; i++) {
    if (brr[i] > 0) {
      if (arr[i] > 0) {
        if (arr[i] > brr[i]) {
          ans = ans + brr[i];
        } else {
          ans = ans + arr[i];
        }
      } else {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 1)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
