#include <bits/stdc++.h>
using namespace std;
int main() {
  map<char, int> a1, b1;
  string a, b;
  int result = 0, flag = 0;
  cin >> a >> b;
  for (auto x : a) a1[x]++;
  for (auto x : b) b1[x]++;
  for (auto x : b1) {
    if (a1.find(x.first) == a1.end()) {
      flag = 1;
      break;
    } else {
      result += min(x.second, a1[x.first]);
    }
  }
  if (flag == 1)
    cout << "-1";
  else
    cout << result;
  return 0;
}
