#include <bits/stdc++.h>
using namespace std;
const int maxn = 400001;
long long arr[maxn], arr2[maxn];
char arr3[maxn];
long long ncr(long long n, long long r) {
  long long ans = 1;
  for (int i = 1; i <= r; i++) {
    ans *= n - i + 1;
    ans /= i;
  }
  return ans;
}
map<long long, set<int> > mop;
vector<long long> vec;
int main() {
  string str, str1;
  long long ans = 0;
  cin >> str >> str1;
  for (int i = 0; i < str.size(); i++) {
    arr[str[i] - 'a']++;
  }
  for (int i = 0; i < str1.size(); i++) {
    arr2[str1[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (arr2[i] && !arr[i]) {
      cout << "-1" << endl;
      return 0;
    }
    ans += min(arr[i], arr2[i]);
  }
  cout << ans << endl;
  return 0;
}
