#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> pcs1(26, 0), pcs2(26, 0);
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < s1.length(); i++) {
    pcs1[s1[i] - 'a']++;
  }
  for (int i = 0; i < s2.length(); i++) {
    pcs2[s2[i] - 'a']++;
  }
  int result = s1.length();
  for (int i = 0; i < 26; i++) {
    pcs1[i] -= pcs2[i];
    if (pcs1[i] + pcs2[i] == 0 && (pcs1[i] != 0 && pcs2[i] != 0)) {
      cout << -1 << endl;
      return 0;
    }
    if (pcs1[i] > 0) {
      result -= pcs1[i];
    }
  }
  cout << result << endl;
  return 0;
}
