#include <bits/stdc++.h>
using namespace std;
int i, r;
string s, g;
int c[256], cg[256];
int main() {
  cin >> s >> g;
  for (auto ch : s) c[ch]++;
  for (auto ch : g) cg[ch]++;
  for (char ch = 'a'; ch <= 'z'; ch++)
    if (cg[ch] > 0) {
      if (c[ch] == 0) {
        r = -1;
        break;
      }
      r += (cg[ch] > c[ch]) ? c[ch] : cg[ch];
    }
  cout << r << endl;
}
