#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int MOD = int(1e9) + 7;
string s1, s2;
int c1[27], c2[27];
int main() {
  cin >> s1 >> s2;
  memset(c1, 0, sizeof(c1));
  memset(c2, 0, sizeof(c2));
  for (int i = 0; i < s1.length(); ++i) c1[s1[i] - 'a']++;
  for (int i = 0; i < s2.length(); ++i) c2[s2[i] - 'a']++;
  int ans = 0;
  bool flag = true;
  for (int i = 0; i < 27; ++i) {
    if (c1[i] > 0 && c2[i] > 0) ans += min(c1[i], c2[i]);
    if (c1[i] == 0 && c2[i] > 0) flag = false;
  }
  if (flag == false) ans = -1;
  printf("%d", ans);
  return 0;
}
