#include <bits/stdc++.h>
using namespace std;
int main() {
  long int i, j, n, n1, n2, a1[1001] = {0}, b1[1001] = {0}, sum = 0;
  char a[1001], b[1001];
  cin >> a;
  cin >> b;
  n1 = strlen(a);
  n2 = strlen(b);
  for (i = 0; i < n1; i++) {
    j = a[i];
    a1[j]++;
  }
  for (i = 0; i < n2; i++) {
    j = b[i];
    b1[j]++;
  }
  for (i = 97; i <= 122; i++) {
    if (a1[i] > b1[i] && b1[i] != 0) {
      sum = sum + b1[i];
    } else if (a1[i] < b1[i] && a1[i] != 0) {
      sum = sum + a1[i];
    } else if (a1[i] == b1[i] && a1[i] == 0) {
      sum = sum;
    } else if (a1[i] == b1[i] && a1[i] != 0) {
      sum = sum + a1[i];
    } else if (a1[i] > b1[i] && b1[i] == 0) {
      sum = sum;
    } else {
      sum = -1;
      break;
    }
  }
  cout << sum;
  return 0;
}
