#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int c[26] = {0}, d[26] = {0};
  cin >> a >> b;
  for (int i = 0; i < a.size(); i++) c[a[i] - 'a']++;
  for (int i = 0; i < b.size(); i++) d[b[i] - 'a']++;
  int t = 0;
  for (int i = 0; i < 26; i++) {
    if (d[i] < c[i])
      t += d[i];
    else if (d[i] != 0) {
      if (c[i])
        t += c[i];
      else {
        cout << "-1";
        return 0;
      }
    }
  }
  cout << t;
}
