#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  while (cin >> s1 >> s2) {
    int len1 = s1.size(), len2 = s2.size();
    int i = 0, j = 0, ans = 0;
    int t1[30] = {0}, t2[30] = {0};
    for (int i = 0; i < len1; ++i) t1[s1[i] - 'a']++;
    for (int i = 0; i < len2; ++i) t2[s2[i] - 'a']++;
    int sum = 0;
    bool ok = 1;
    for (int i = 0; i < 26; ++i)
      if (t2[i] != 0 && t1[i] == 0) {
        ok = 0;
        break;
      }
    for (int i = 0; i < 27; ++i)
      if (t2[i] != 0) {
        if (t2[i] <= t1[i])
          sum += t2[i];
        else
          sum += t1[i];
      }
    if (!ok) sum = -1;
    cout << sum << endl;
  }
  return 0;
}
