#include <bits/stdc++.h>
using namespace std;
int a[27];
int a1[27];
int main() {
  char s[1010];
  char s1[1010];
  scanf("%s", s);
  scanf("%s", s1);
  int d = strlen(s);
  for (int i = 0; i < d; i++) {
    a[s[i] - 'a']++;
  }
  int d1 = strlen(s1);
  for (int i = 0; i < d1; i++) {
    a1[s1[i] - 'a']++;
  }
  int sum = 0, flag = 0;
  for (int i = 0; i < 26; i++) {
    if (a[i] == 0 && a1[i] > 0)
      flag = 1;
    else
      sum = sum + min(a[i], a1[i]);
  }
  if (flag) sum = -1;
  cout << sum << endl;
}
