#include <bits/stdc++.h>
using namespace std;
const int n = 26;
int main() {
  string str1, str2;
  char abc[] = {"abcdefghijklmnopqrstuvwxyz"};
  int arr1[n] = {0}, arr2[n] = {0}, i, j, max = 0;
  cin >> str1 >> str2;
  for (i = 0; i < n; i++) {
    for (j = 0; str1[j] != '\0'; j++) {
      if (abc[i] == str1[j]) arr1[i]++;
    }
    for (j = 0; str2[j] != '\0'; j++) {
      if (abc[i] == str2[j]) arr2[i]++;
    }
  }
  for (i = 0; i < n; i++) {
    if (arr2[i] <= arr1[i]) max += arr2[i];
    if (arr2[i] > arr1[i]) {
      if (arr2[i] - arr1[i] == arr2[i]) {
        max = -1;
        break;
      } else
        max += arr1[i];
    }
  }
  cout << max;
  return 0;
}
