#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int have[300], need[300];
int main() {
  char a[N];
  char b[N];
  scanf("%s%s", a, b);
  for (int i = 0; a[i] != '\0'; i++) have[a[i]]++;
  for (int j = 0; b[j] != '\0'; j++) need[b[j]]++;
  int ans = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    if (have[i] == 0 && need[i] != 0) {
      ans = -1;
      break;
    }
    ans += min(have[i], need[i]);
  }
  printf("%d\n", ans);
  return 0;
}
