#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double PI = acos(-1 + .0);
using namespace std;
char sa[1005];
char sb[1005];
int a[30], b[30];
int main() {
  while (scanf("%s%s", sa, sb) != EOF) {
    int la = strlen(sa);
    int lb = strlen(sb);
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < la; i++) {
      a[sa[i] - 'a']++;
    }
    for (int i = 0; i < lb; i++) {
      b[sb[i] - 'a']++;
    }
    int sum = 0, flag = 0;
    for (int i = 0; i < 26; i++) {
      if (a[i] == 0 && b[i] != 0) {
        flag = 1;
        printf("-1\n");
        break;
      }
      if (a[i] != 0 && b[i] != 0) {
        if (a[i] < b[i])
          sum += a[i];
        else
          sum += b[i];
      }
    }
    if (flag == 0) printf("%d\n", sum);
  }
  return 0;
}
