#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[26], b[26];
  memset(a, 0, sizeof a);
  memset(b, 0, sizeof b);
  string s, t;
  cin >> s >> t;
  for (char c : s) a[c - 'a']++;
  for (char c : t) b[c - 'a']++;
  int tot = 0;
  for (int i = 0; i < 26; i++) {
    if (b[i] && a[i] == 0) {
      cout << -1;
      exit(0);
    } else {
      tot += min(a[i], b[i]);
    }
  }
  cout << tot;
  return 0;
}
