#include <bits/stdc++.h>
using namespace std;
int aa[30], bb[30];
int main() {
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < a.length(); i++) aa[a[i] - 'a']++;
  for (int i = 0; i < b.length(); i++) bb[b[i] - 'a']++;
  int s = 0;
  for (int i = 0; i < 30; i++) {
    if (aa[i] == 0 && bb[i] > 0) {
      cout << -1;
      return 0;
    }
    s += min(aa[i], bb[i]);
  }
  cout << s;
}
