#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s1, s2;
  cin >> s1 >> s2;
  long long a[26] = {0}, b[26] = {0};
  for (long long i = 0; i < s1.length(); i++) {
    long long idx = s1[i] - 'a';
    a[idx]++;
  }
  for (long long i = 0; i < s2.length(); i++) {
    long long idx = s2[i] - 'a';
    b[idx]++;
  }
  long long flg = 1;
  for (long long i = 0; i < s2.length(); i++) {
    long long val = s2[i] - 'a';
    if (a[val] == 0) {
      flg = 0;
      break;
    }
  }
  if (!flg)
    cout << -1;
  else if (flg) {
    long long sum = 0;
    for (long long i = 0; i < 26; i++) {
      sum += min(a[i], b[i]);
    }
    cout << sum;
  }
}
