#include <bits/stdc++.h>
using namespace std;
int v[200], v1[200];
int main() {
  ios::sync_with_stdio(false);
  string s1, s2;
  cin >> s1 >> s2;
  memset(v, 0, sizeof(v));
  memset(v1, 0, sizeof(v1));
  for (int i = 0; i < s1.size(); i++) {
    v[(int)(s1[i] - 'a')]++;
  }
  for (int i = 0; i < s2.size(); i++) {
    v1[(int)(s2[i] - 'a')]++;
  }
  long long res = 0;
  for (int i = 0; i < 26; i++) {
    if (v1[i] && !v[i]) {
      cout << -1 << "\n";
      return 0;
    }
    res += min(v[i], v1[i]);
  }
  cout << res << "\n";
}
