#include <bits/stdc++.h>
using namespace std;
char linea[1010];
char lineb[1010];
int m[1010][1010];
int ta, tb;
int leta[30], letb[30];
void printM() {
  for (int i = 0; i < ta + 1; i++) {
    for (int j = 0; j < tb + 1; j++) {
      printf("%d", m[i][j]);
    }
    puts("");
  }
}
int main() {
  gets(linea);
  gets(lineb);
  ta = strlen(linea);
  tb = strlen(lineb);
  int res = 0;
  memset(leta, 0, sizeof(leta));
  memset(letb, 0, sizeof(letb));
  for (int i = 0; i < ta; i++) {
    leta[linea[i] - 'a']++;
  }
  for (int i = 0; i < tb; i++) {
    letb[lineb[i] - 'a']++;
  }
  res = 0;
  for (int i = 0; i < 26; i++) {
    if (letb[i]) res += min(leta[i], letb[i]);
    if (!leta[i] && letb[i]) {
      res = 0;
      break;
    }
  }
  if (res == 0)
    puts("-1");
  else
    printf("%d\n", res);
  return 0;
}
