#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  int vasya[255] = {0};
  int gard[255] = {0};
  for (int i = 0; i < s1.length(); i++) {
    vasya[s1[i]]++;
  }
  for (int i = 0; i < s2.length(); i++) {
    gard[s2[i]]++;
  }
  for (int i = 0; i < 255; i++) {
    if ((vasya[i] == 0 && gard[i] != 0)) {
      cout << -1;
      return (0);
    }
  }
  int count = 0;
  for (int i = 0; i < 255; i++) {
    count = count + min(vasya[i], gard[i]);
  }
  cout << count;
  return (0);
}
