#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  char dt[1002];
  memset(dt, 0, sizeof(dt));
  char gr[1002];
  memset(gr, 0, sizeof(gr));
  cin >> dt >> gr;
  int n = strlen(dt);
  int m = strlen(gr);
  map<char, int> dtc;
  map<char, int> gtc;
  for (int i = 0; i < n; ++i) {
    dtc[dt[i]]++;
  }
  for (int i = 0; i < m; ++i) {
    gtc[gr[i]]++;
  }
  int res = 0;
  map<char, int>::iterator it;
  for (it = gtc.begin(); it != gtc.end(); ++it) {
    char val = it->first;
    if (dtc[val] == 0) {
      cout << -1;
      return 0;
    }
    if (dtc[val] >= gtc[val])
      res += gtc[val];
    else
      res += dtc[val];
  }
  cout << res << endl;
  return 0;
}
