#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  map<char, long long> m, n;
  for (long long i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  for (long long i = 0; i < t.size(); i++) {
    n[t[i]]++;
  }
  long long sum = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    if (m[c] == 0 && n[c] != 0) {
      cout << -1 << endl;
      return 0;
    }
    sum += min(m[c], n[c]);
  }
  cout << sum << endl;
  return 0;
}
