#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  vector<int> source(26), need(26);
  for (int i = 0; i < s1.size(); ++i) {
    ++source[s1[i] - 'a'];
  }
  for (int i = 0; i < s2.size(); ++i) {
    ++need[s2[i] - 'a'];
  }
  int ans = 0;
  bool f = false;
  for (int i = 0; i < 26; ++i) {
    if (need[i] != 0) {
      if (source[i] == 0) {
        f = true;
        break;
      } else {
        if (need[i] < source[i]) {
          ans += need[i];
        } else {
          ans += source[i];
        }
        need[i] = 0;
      }
    }
  }
  if (f) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
