#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s1, s2;
  cin >> s1 >> s2;
  map<char, long long> m;
  long long c = 0;
  map<char, long long> n;
  for (long long j = 0; j < s1.size(); j++) m[s1[j]]++;
  for (long long j = 0; j < s2.size(); j++) n[s2[j]]++;
  for (long long j = 0; j < s2.size(); j++) {
    if (m[s2[j]] == 0) {
      cout << -1;
      return 0;
    } else if (m[s2[j]] != -1) {
      c += min(m[s2[j]], n[s2[j]]);
      m[s2[j]] = -1;
    }
  }
  cout << c;
  return 0;
}
