#include <bits/stdc++.h>
int main() {
  char a[1010], b[1010];
  int ai[26] = {0}, bi[26] = {0}, la, lb, count = 0;
  int i, t = 1;
  scanf("%s", a);
  scanf("%s", b);
  la = strlen(a);
  lb = strlen(b);
  for (i = 0; i < la; i++) ai[a[i] - 'a']++;
  for (i = 0; i < lb; i++) bi[b[i] - 'a']++;
  for (i = 0; i < 26; i++) {
    if (!ai[i] && bi[i]) {
      t = 0;
      break;
    }
    count += ai[i] < bi[i] ? ai[i] : bi[i];
  }
  if (count == 0) t = 0;
  if (t)
    printf("%d\n", count);
  else
    printf("-1\n");
  return 0;
}
