#include <bits/stdc++.h>
using namespace std;
int x[33], y[33];
int main() {
  int ans = 0;
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < (int)s1.size(); ++i) x[s1[i] - 'a']++;
  for (int i = 0; i < (int)s2.size(); ++i) y[s2[i] - 'a']++;
  bool flag = true;
  for (int i = 0; i < 33; ++i) {
    if (y[i] != 0) {
      if (x[i] == 0) {
        flag = false;
        break;
      } else {
        ans += min(x[i], y[i]);
      }
    }
  }
  if (!flag)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
