#include <bits/stdc++.h>
using namespace std;
int main() {
  string n, m;
  cin >> n;
  cin >> m;
  int s = 0, a[26] = {0}, b[26] = {0};
  for (int i = 0; n[i] >= 'a' && n[i] <= 'z'; ++i) ++a[int(n[i]) - int('a')];
  for (int i = 0; m[i] >= 'a' && m[i] <= 'z'; ++i) ++b[int(m[i]) - int('a')];
  for (int i = 0; i < 26 && s != -1; ++i) {
    s += a[i] * (a[i] <= b[i]) + b[i] * (a[i] > b[i]);
    if (a[i] == 0 && b[i] != 0) s = -1;
  }
  cout << s;
  return 0;
}
