#include <bits/stdc++.h>
using namespace std;
int input[26];
int output[26];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < (int)s1.size(); i++) input[(int)(s1.at(i) - 97)]++;
  for (int i = 0; i < (int)s2.size(); i++) output[(int)(s2.at(i) - 97)]++;
  int sum = 0;
  for (int i = 0; i < 26; i++) {
    if (input[i] == 0 && output[i] > 0) {
      cout << -1;
      return 0;
    }
    if (input[i] >= output[i])
      sum += output[i];
    else
      sum += input[i];
  }
  cout << sum;
  return 0;
}
