#include <bits/stdc++.h>
using namespace std;
void solve() {
  string n, m;
  cin >> n >> m;
  map<char, int> a, b;
  for (char ch : n) {
    a[ch]++;
  }
  for (char ch : m) {
    b[ch]++;
  }
  int flag = 0;
  double sum = 0;
  for (auto it = b.begin(); it != b.end(); it++) {
    auto i = a.find(it->first);
    if (i == a.end()) {
      flag = 1;
      break;
    } else {
      if (i->second >= it->second) {
        sum += it->second;
      } else {
        sum += i->second;
      }
    }
  }
  if (flag == 0)
    cout << sum << endl;
  else {
    cout << -1 << endl;
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  for (long long int i = 0; i < (t); i++) {
    solve();
  }
  return 0;
}
