#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[1002], b[1002];
  cin >> a;
  cin >> b;
  int have[27], want[27];
  memset(have, 0, sizeof have);
  memset(want, 0, sizeof want);
  for (int i = 0; i < strlen(a); i++) {
    have[((int)a[i]) - 97]++;
  }
  for (int i = 0; i < strlen(b); i++) {
    want[((int)b[i]) - 97]++;
  }
  int ans = 0;
  for (int i = 0; i < 27; i++) {
    if (have[i] == 0 && want[i] != 0) {
      cout << "-1" << endl;
      return 0;
    } else
      ans += min(have[i], want[i]);
  }
  cout << ans << endl;
  return 0;
}
