#include <bits/stdc++.h>
using namespace std;
int main() {
  string n, m;
  cin >> n >> m;
  map<char, int> m1;
  map<char, int> m2;
  char x = 'a';
  for (int i = 0; i < 26; i++) {
    m1[x] = 0;
    x++;
  }
  for (int i = 0; i < n.length(); i++) m1[n[i]]++;
  for (int i = 0; i < m.length(); i++) m2[m[i]]++;
  int ans = 0;
  map<char, int>::iterator it;
  for (it = m2.begin(); it != m2.end(); it++) {
    if (m1[it->first] > m2[it->first])
      ans += m2[it->first];
    else if (m1[it->first] != 0)
      ans += m1[it->first];
    else {
      cout << "-1";
      return 0;
    }
  }
  cout << ans;
  return 0;
}
