#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int maxn = 1000 + 10;
char a[maxn], b[maxn];
int num1[40], num2[40];
int main() {
  scanf("%s", a);
  scanf("%s", b);
  int len = strlen(a);
  memset(num1, 0, sizeof num1);
  memset(num2, 0, sizeof num2);
  for (int i = 0; i < len; i++) {
    int s = a[i] - 'a';
    num1[s]++;
  }
  len = strlen(b);
  for (int i = 0; i < len; i++) {
    int s = b[i] - 'a';
    num2[s]++;
  }
  int ans = 0;
  bool flag = 1;
  for (int i = 0; i < 26; i++) {
    if (num2[i] > 0 && num1[i] == 0) {
      flag = 0;
      break;
    }
    ans += min(num1[i], num2[i]);
  }
  if (flag == 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
  return 0;
}
