#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  string m;
  cin >> m;
  sort(m.begin(), m.end());
  int cn = 0;
  int cm = 0;
  int res = 0;
  for (int i = 0; i < m.length(); i += cm) {
    cm = count(m.begin(), m.end(), m[i]);
    cn = count(n.begin(), n.end(), m[i]);
    if (cn == 0) {
      cout << -1;
      return 0;
    } else if (cn >= cm)
      res += cm;
    else
      res += cn;
  }
  cout << res;
  return 0;
}
