#include <bits/stdc++.h>
using namespace std;
long long fr1[30], fr2[30];
int main() {
  long long n, m, i, j, l1, l2, ans = 0;
  string s1, s2;
  cin >> s1 >> s2;
  l1 = s1.size(), l2 = s2.size();
  for (i = 0; i < l1; i++) fr1[s1[i] - 'a']++;
  for (i = 0; i < l2; i++) fr2[s2[i] - 'a']++;
  for (i = 0; i < 26; i++) {
    if (fr2[i] && fr1[i] == 0) {
      printf("-1\n");
      return 0;
    }
    ans += min(fr1[i], fr2[i]);
  }
  printf("%lld", ans), printf("\n");
}
