#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  map<char, int> m1, m2, m3;
  for (int i = 0; i < a.length(); i++) {
    m1[a[i]]++;
  }
  for (int i = 0; i < b.length(); i++) {
    m2[b[i]]++;
  }
  int f = 0;
  long long ans = 0;
  for (int i = 0; i < b.length(); i++) {
    if (m1[b[i]] == 0) {
      f = 1;
      break;
    } else {
      if (m3[b[i]] == 0) {
        m3[b[i]] = 1;
        ans += min(m1[b[i]], m2[b[i]]);
      }
    }
  }
  if (f)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
