#include <bits/stdc++.h>
using namespace std;
long long a[398178], b[456565], c[546545], n, m, z, t, u, d[54][45], l, s, h, i,
    j, k, x, y, r, tt, tc, ct, cc;
string p, q;
int main() {
  cin >> p;
  cin >> q;
  n = p.size();
  m = q.size();
  for (i = 0; i < 26; i++) {
    a[i] = 0;
    b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    a[p[i] - 97]++;
  }
  for (i = 0; i < m; i++) {
    b[q[i] - 97]++;
  }
  for (i = 0; i < 26; i++) {
    s += min(a[i], b[i]);
    if (b[i] > 0 && a[i] == 0) {
      cout << -1;
      return 0;
    }
  }
  cout << s;
}
