#include <bits/stdc++.h>
using namespace std;
int cont[1003], sum[1003];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int ans = 0;
  string s1, s2;
  cin >> s1 >> s2;
  int n = s1.size();
  int m = s2.size();
  for (int i = 0; i < n; i++) cont[s1[i] - 'a']++;
  for (int i = 0; i < m; i++) sum[s2[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (sum[i] > 0 && cont[i] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    if (sum[i] > cont[i])
      ans += cont[i];
    else
      ans += sum[i];
  }
  cout << ans << '\n';
  return 0;
}
