#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  while (cin >> a >> b) {
    map<char, int> n;
    map<char, int> m;
    for (int i = 0; i < a.length(); ++i) {
      n[a[i]]++;
    }
    for (int i = 0; i < b.length(); ++i) {
      m[b[i]]++;
    }
    long long sum = 0;
    map<char, int>::iterator n1 = n.begin();
    map<char, int>::iterator m1 = m.begin();
    int f = 0;
    while (n1 != n.end() && m1 != m.end()) {
      if (n1->first > m1->first) {
        f = 1;
        break;
      } else if (n1->first == m1->first) {
        sum += min(n1->second, m1->second);
        n1++;
        m1++;
      } else
        n1++;
    }
    if (f == 1 || sum == 0) sum = -1;
    cout << sum << endl;
  }
  return 0;
}
