#include <bits/stdc++.h>
using namespace std;
int a1[1025];
int a2[1025];
int main() {
  string s, t, x;
  int cm = 0, xm = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    a1[(int)s[i]]++;
  }
  for (int i = 0; i < t.size(); i++) {
    a2[(int)t[i]]++;
  }
  for (int i = 97; i <= 122; i++) {
    if (a2[i] != 0) cm++;
    if (a1[i] != 0 && a2[i] != 0) {
      xm++;
      while (a1[i]-- && a2[i]--) {
        x += (char)i;
      }
    }
  }
  int r = x.size();
  if (r == 0)
    cout << "-1";
  else {
    if (cm > xm)
      cout << "-1";
    else
      cout << r;
  }
  return 0;
}
