#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e3 + 10;
int a[maxx], b[maxx];
int main() {
  std::ios::sync_with_stdio(false);
  string s, ss;
  cin >> s >> ss;
  for (int i = 0; i < s.size(); i++) {
    int x = (s[i] - 'a');
    a[x]++;
  }
  for (int i = 0; i < ss.size(); i++) {
    int x = (ss[i] - 'a');
    b[x]++;
  }
  int ans = 0;
  int flag = 0;
  for (int i = 0; i < 26; i++) {
    ans += min(a[i], b[i]);
    if (a[i] == 0 && b[i]) flag = 1;
  }
  if (ans == 0 || flag)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
