#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, int> x;
  map<char, int> y;
  map<char, bool> y3;
  map<char, bool> y2;
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < s1.size(); ++i) x[s1[i]]++;
  for (int i = 0; i < s2.size(); ++i) {
    y3[s2[i]] = 1;
    y[s2[i]]++;
  }
  int res = 0;
  for (map<char, int>::iterator it = y.begin(); it != y.end(); ++it) {
    int z = min(it->second, x[it->first]);
    if (z > 0) y2[it->first] = 1;
    res += z;
  }
  if (!res)
    cout << -1 << endl;
  else if (y2.size() != y3.size())
    cout << -1 << endl;
  else
    cout << res << endl;
}
