#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
ll inf = 1e16;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  ll x, n, i, y, j, t, xx = 0;
  string s, s1;
  map<char, ll> mp, mp1;
  cin >> s >> s1;
  for (i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  for (i = 0; i < s1.size(); i++) {
    mp1[s1[i]]++;
  }
  ll sum = 0;
  for (char j = 'a'; j <= 'z'; j++) {
    if (mp[j] == 0 && mp1[j] > 0) {
      xx = 1;
    }
    sum += min(mp[j], mp1[j]);
  }
  if (sum == 0 || xx == 1)
    cout << -1 << endl;
  else
    cout << sum << endl;
}
