#include <bits/stdc++.h>
using namespace std;
string poss, req;
int fqp[26], fqr[26];
int main() {
  cin >> poss >> req;
  for (int i = 0; i < req.size(); ++i) {
    if (poss.find(req[i]) == -1) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < req.size(); i++) {
    ++fqr[req[i] - 'a'];
  }
  for (int i = 0; i < poss.size(); i++) {
    ++fqp[poss[i] - 'a'];
  }
  int s = 0;
  for (int i = 0; i < 26; i++) {
    s += min(fqp[i], fqr[i]);
  }
  cout << s;
  return 0;
}
