#include <bits/stdc++.h>
using namespace std;
string N, M;
int Chars1[26], Chars2[26];
int Ans = 0;
int main() {
  cin >> N >> M;
  for (int i = 0; i < max(N.size(), M.size()); i++) {
    if (i < N.size()) Chars1[N[i] - 'a']++;
    if (i < M.size()) Chars2[M[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if ((Chars1[i] == 0) && (Chars2[i] != 0)) {
      Ans = -1;
      break;
    }
    Ans += min(Chars1[i], Chars2[i]);
  }
  cout << Ans << endl;
}
