#include <bits/stdc++.h>
int main() {
  char arr[1005];
  char brr[1005];
  scanf("%s", arr);
  scanf("%s", brr);
  int i, c = 0;
  int num1[26] = {0};
  int num2[26] = {0};
  for (i = 0; arr[i] != '\0'; ++i) num1[arr[i] - 97]++;
  for (i = 0; brr[i] != '\0'; ++i) num2[brr[i] - 97]++;
  for (i = 0; i < 26; ++i) {
    if (num1[i] == 0 && num2[i] != 0)
      break;
    else if (num1[i] != 0 && num2[i] == 0)
      ;
    else if (num1[i] <= num2[i])
      c += num1[i];
    else if (num1[i] > num2[i])
      c += num2[i];
  }
  if (i < 26)
    printf("%d", -1);
  else
    printf("%d", c);
  return 0;
}
