#include <bits/stdc++.h>
int main() {
  char c;
  int flag, area, i;
  int count1[27] = {0};
  int count2[27] = {0};
  flag = 0;
  area = 0;
  while ((c = getchar()) != '\n' || flag != 1) {
    if (c == '\n') {
      flag = 1;
      continue;
    }
    if (flag == 0)
      count1[c - 97]++;
    else
      count2[c - 97]++;
  }
  flag = 26;
  i = 0;
  while (flag--) {
    if (count2[i] >= count1[i]) {
      if (count1[i] != 0) area += count1[i];
    }
    if (count2[i] < count1[i]) area += count2[i];
    if (count2[i] != 0 && count1[i] == 0) {
      area = -1;
      break;
    }
    i++;
  }
  printf("%d\n", area);
  return 0;
}
