#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  while (cin >> s >> s1) {
    int l = s.size();
    int l1 = s1.size();
    map<char, int> mp, mp1;
    for (int i = 0; i < l; i++) {
      mp[s[i]]++;
    }
    for (int i = 0; i < l1; i++) {
      mp1[s1[i]]++;
    }
    map<char, int>::iterator it;
    int cnt = 0;
    bool b = 1;
    for (it = mp1.begin(); it != mp1.end(); it++) {
      if (mp[it->first] == 0) {
        b = 0;
      } else if (it->second <= mp[it->first]) {
        cnt += it->second;
      } else {
        cnt += mp[it->first];
      }
    }
    if (b == 0) {
      cout << -1 << endl;
    } else {
      cout << cnt << endl;
    }
  }
  return 0;
}
