#include <bits/stdc++.h>
using namespace std;
int MIN(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int main() {
  int i, l1, l2;
  char s1[1002], s2[1002];
  scanf("%s", s1);
  scanf("%s", s2);
  int a1[28] = {0};
  int a2[28] = {0};
  for (i = 0; s1[i]; i++) {
    a1[s1[i] - 97]++;
  }
  for (i = 0; s2[i]; i++) {
    a2[s2[i] - 97] = a2[s2[i] - 97] + 1;
  }
  long long int sum = 0;
  int flag = 0;
  for (i = 0; i < 28; i++) {
    sum = sum + MIN(a1[i], a2[i]);
    if (a1[i] == 0 && a2[i] > 0) flag = 1;
  }
  if (flag == 0)
    cout << sum;
  else
    printf("-1");
  return 0;
}
