#include <bits/stdc++.h>
using namespace std;
char x[1005];
char y[1005];
int a[1005], b[1005];
int main() {
  while (scanf("%s%s", x, y) != EOF) {
    int l1 = strlen(x);
    int l2 = strlen(y);
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < l1; i++) {
      a[x[i] - 'a']++;
    }
    for (int i = 0; i < l2; i++) {
      b[y[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);
  }
}
