#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string str1;
  string str2;
  cin >> str1;
  cin >> str2;
  int s1 = str1.size();
  int s2 = str2.size();
  vector<int> arr1(123, 0);
  vector<int> arr2(123, 0);
  for (int i = 0; i < s1; i++) {
    arr1[int(str1[i])]++;
  }
  for (int i = 0; i < s2; i++) {
    arr2[int(str2[i])]++;
  }
  int total = 0;
  for (int i = 97; i < 123; i++) {
    if (arr2[i] > 0 && arr1[i] == 0) {
      cout << -1;
      exit(0);
    }
    total += min(arr1[i], arr2[i]);
  }
  if (total > 0) {
    cout << total;
  } else {
    cout << -1;
  }
}
