#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[26] = {}, arr2[26] = {}, ans = 0;
  string s, s2;
  cin >> s >> s2;
  for (int i = 0; i < max(s.size(), s2.size()); i++) {
    if (i < s.size()) arr[s[i] - 'a']++;
    if (i < s2.size()) arr2[s2[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (arr2[i] >= arr[i] && arr[i] != 0)
      ans += arr[i];
    else if (arr2[i] < arr[i] && arr2[i] != 0)
      ans += arr2[i];
    else if (arr2[i] > arr[i] && arr[i] == 0)
      return cout << "-1\n", 0;
  }
  cout << ans << "\n";
  return 0;
}
