#include <bits/stdc++.h>
using namespace std;
string w, p;
int counter, wV[26], pV[26];
int main() {
  cin >> p >> w;
  for (int i = 0; i < p.length(); i++) pV[p[i] - 'a']++;
  for (int i = 0; i < w.length(); i++) wV[w[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (wV[i] > 0 && pV[i] == 0) {
      cout << "-1";
      return 0;
    }
    counter += min(wV[i], pV[i]);
  }
  cout << counter;
  return 0;
}
