#include <bits/stdc++.h>
char str1[2005];
char str2[2005];
int num1[30];
int num2[30];
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int main() {
  scanf("%s%s", str1, str2);
  memset(num1, 0, sizeof(num1));
  memset(num2, 0, sizeof(num2));
  int len1 = strlen(str1);
  int len2 = strlen(str2);
  for (int i = 0; i < len1; i++) {
    num1[str1[i] - 'a']++;
  }
  for (int i = 0; i < len2; i++) {
    num2[str2[i] - 'a']++;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans += min(num1[i], num2[i]);
  }
  for (int i = 0; i < 26; i++) {
    if (num2[i] > 0 && num1[i] == 0) {
      ans = -1;
      break;
    }
  }
  if (ans <= 0)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
