#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int h1[26] = {0};
  int h2[26] = {0};
  int sum = 0, i;
  string s1, s2;
  cin >> s1 >> s2;
  for (i = 0; i < s1.length(); ++i) h1[s1[i] - 97]++;
  for (i = 0; i < s2.length(); ++i) h2[s2[i] - 97]++;
  for (i = 0; i < 26; ++i) {
    sum += min(h1[i], h2[i]);
    if (h2[i] > 0 && h1[i] == 0) break;
  }
  if (sum == 0 || i < 26)
    cout << -1;
  else
    cout << sum;
  return 0;
}
