#include <bits/stdc++.h>
char in[1000], op[1000];
using namespace std;
int *getCharCount(char *str) {
  int *count = (int *)calloc(256, sizeof(int));
  for (int i = 0; *(str + i); i++) {
    count[*(str + i)]++;
  }
  return count;
}
int main() {
  scanf("%s", in);
  scanf("%s", op);
  int *count = getCharCount(in);
  int *ot = getCharCount(op);
  int sum = 0, ref = 0;
  for (int i = 0; i < 256; i++) {
    if (count[i] > 0 && ot[i] > 0) {
      if (count[i] > ot[i])
        sum += ot[i];
      else
        sum += count[i];
    }
    if (count[i] == 0 && ot[i] > 0) {
      ref = 1;
      break;
    }
  }
  free(count);
  free(ot);
  if (ref == 1)
    cout << "-1" << endl;
  else
    cout << sum << endl;
  return 0;
}
