#include <bits/stdc++.h>
using namespace std;
int main() {
  char s1[1005], s2[1005];
  int c1[30], c2[30];
  memset(c1, 0, sizeof(c1));
  memset(c2, 0, sizeof(c2));
  scanf("%s%s", s1, s2);
  for (int i = 0; i < strlen(s1); ++i) c1[s1[i] - 'a']++;
  for (int i = 0; i < strlen(s2); ++i) c2[s2[i] - 'a']++;
  int sum = 0;
  for (int i = 0; i < 26; ++i) {
    if (c2[i] && !c1[i]) {
      sum = -1;
      break;
    }
    sum += min(c2[i], c1[i]);
  }
  printf("%d\n", sum);
  return 0;
}
