#include <bits/stdc++.h>
using namespace std;
char n[1000 + 2];
char m[1000 + 2];
int color_n[30];
int color_m[30];
int main() {
  while (scanf("%s", n) != EOF) {
    scanf("%s", m);
    memset(color_n, 0, sizeof(color_n));
    memset(color_m, 0, sizeof(color_m));
    for (int i = 0; i < strlen(n); i++) color_n[n[i] - 'a']++;
    for (int j = 0; j < strlen(m); j++) color_m[m[j] - 'a']++;
    int ans = 0;
    int flag = 1;
    for (int i = 0; i < 30; i++) {
      ans += min(color_n[i], color_m[i]);
      if (color_m[i] && color_n[i] == 0) flag = 0;
    }
    if (ans == 0 || flag == 0)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
