#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 128;
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int g1[26], g2[26];
  memset(g1, 0, sizeof(g1));
  memset(g2, 0, sizeof(g2));
  for (int i = 0; i < s1.size(); ++i) g1[s1[i] - 'a']++;
  for (int i = 0; i < s2.size(); ++i) g2[s2[i] - 'a']++;
  int ans = 0;
  bool flag = false;
  for (int i = 0; i < 26; ++i) {
    if (g1[i] == 0 && g2[i] > 0) {
      flag = true;
      break;
    } else if (g1[i] < g2[i])
      ans += g1[i];
    else {
      ans += g2[i];
    }
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
