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