#include <bits/stdc++.h>
using namespace std;
char a[1111], b[1111];
int sa[30], sb[30];
int main() {
  int n;
  gets(a);
  gets(b);
  int lena = strlen(a), lenb = strlen(b);
  memset(sa, 0, sizeof(sa));
  memset(sb, 0, sizeof(sb));
  for (int i = 0; i < lena; i++) {
    sa[a[i] - 'a']++;
  }
  for (int i = 0; i < lenb; i++) {
    sb[b[i] - 'a']++;
  }
  int ans = 0;
  int i;
  for (i = 0; i < 26; i++) {
    if (sb[i] < sa[i])
      ans += sb[i];
    else
      ans += sa[i];
    if (sa[i] == 0 && sb[i] != 0) break;
  }
  if (ans == 0 || i < 26)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
