#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, int> mp;
  long long total = 0;
  string a, s;
  cin >> a >> s;
  long long m = s.length();
  for (int i = 0; i < a.length(); i++) {
    mp[a[i]]++;
  }
  for (int i = 0; i < m; i++) {
    if (mp[s[i]] > 1) {
      total++;
      mp[s[i]]--;
    } else if (mp[s[i]] == 1) {
      total++;
      mp[s[i]] = -1;
    } else if (mp[s[i]] == 0) {
      cout << "-1";
      return 0;
    }
  }
  cout << total;
}
