#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void mainHelper() {
  string a;
  string b;
  cin >> a;
  cin >> b;
  int arr[26] = {};
  int arr1[26] = {};
  for (char c : a) arr[c - 'a']++;
  for (char c : b) arr1[c - 'a']++;
  int res = 0;
  for (int i = 0; i < 26; i++) {
    if (arr1[i] == 0) continue;
    int count = min(arr1[i], arr[i]);
    if (count == 0) {
      res = -1;
      break;
    }
    res += count;
  }
  cout << res << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  mainHelper();
  return 0;
}
