#include <bits/stdc++.h>
using namespace std;
void FindOcc(int x[], string a) {
  memset(x, 0, 26 * 4);
  for (int i = 0; i < a.size(); i++) {
    x[a[i] - 'a']++;
  }
}
int main() {
  string a, b;
  cin >> a >> b;
  int papers[26], garland[26];
  FindOcc(papers, a);
  FindOcc(garland, b);
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    if (papers[i] >= garland[i]) {
      ans += garland[i];
    } else {
      if (papers[i] != 0)
        ans += papers[i];
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (ans == 0)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
