#include <bits/stdc++.h>
using namespace std;
int arr[51111], arr2[1000];
vector<pair<long long, long long> > vec;
vector<long long> ans;
int main() {
  string str, str2;
  cin >> str >> str2;
  long long ans = 0;
  for (int i = 0; i < str.size(); i++) {
    arr[str[i] - 'a']++;
  }
  for (int i = 0; i < str2.size(); i++) {
    arr2[str2[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (arr2[i]) {
      if (!arr[i]) {
        cout << "-1" << endl;
        return 0;
      }
      ans += min(arr2[i], arr[i]);
    }
  }
  cout << ((ans == 0) ? -1 : ans) << endl;
  return 0;
}
