#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b;
  int ca[26] = {0}, cb[26] = {0};
  cin >> a >> b;
  for (int i = 0; a[i] != '\0'; i++) ca[a[i] - 97]++;
  for (int i = 0; b[i] != '\0'; i++) cb[b[i] - 97]++;
  int area = 0;
  for (int i = 0; i < 26; i++) {
    if (cb[i] != 0 && ca[i] == 0) {
      cout << -1;
      return 0;
    } else if (cb[i] == ca[i])
      area += cb[i];
    else if (cb[i] > ca[i])
      area += ca[i];
    else if (cb[i] < ca[i])
      area += cb[i];
  }
  cout << area;
  return 0;
}
