#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, ans = 0, k, q = 0;
  string n, m;
  cin >> n >> m;
  int l1 = n.length();
  int l2 = m.length();
  int a[1003] = {0}, b[1003] = {0};
  for (i = 0; i < l1; i++) {
    k = n[i] - '0' - 48;
    a[k]++;
  }
  for (i = 0; i < l2; i++) {
    k = m[i] - '0' - 48;
    b[k]++;
  }
  for (i = 0; i < 30; i++) {
    if (a[i] >= b[i])
      ans += b[i];
    else if (a[i] < b[i])
      ans += a[i];
    if (a[i] == 0 && b[i] > 0) q = 5;
  }
  if (ans == 0 || q == 5)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
