#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[1000000] = {}, b[1000000] = {};
  cin >> a >> b;
  int c1[30] = {}, c2[30] = {};
  for (int i = 0; i < strlen(a); i++) c1[a[i] - 97]++;
  for (int i = 0; i < strlen(b); i++) c2[b[i] - 97]++;
  for (int i = 0; i < 30; i++)
    if (c2[i] != 0 && c1[i] == 0) {
      cout << -1;
      return 0;
    }
  int ans = 0;
  for (int i = 0; i < 30; i++)
    if (c2[i] != 0) ans += min(c1[i], c2[i]);
  cout << ans;
}
