#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int i, j, t1, t2, ans = 0;
  cin >> a >> b;
  for (i = 0; i < 26; i++) {
    t1 = t2 = 0;
    for (j = 0; j < a.size(); j++) t1 += a[j] == 'a' + i;
    for (j = 0; j < b.size(); j++) t2 += b[j] == 'a' + i;
    if (t2 && !t1) {
      ans = -1;
      break;
    }
    ans += min(t1, t2);
  }
  cout << ans << endl;
}
