#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
char s1[maxn];
char s2[maxn];
int n1[27];
int n2[27];
int main() {
  while (cin >> s1) {
    cin >> s2;
    memset(n1, 0, sizeof(n1));
    memset(n2, 0, sizeof(n2));
    for (int i = 0; i < strlen(s1); i++) {
      n1[s1[i] - 'a' + 1]++;
    }
    for (int i = 0; i < strlen(s2); i++) {
      n2[s2[i] - 'a' + 1]++;
    }
    int flag = 1;
    int ans = 0;
    for (int i = 1; i <= 26; i++) {
      if (n1[i] != 0 && n2[i] != 0)
        ans += min(n1[i], n2[i]);
      else if (n2[i] != 0 && n1[i] == 0) {
        flag = 0;
        break;
      }
    }
    if (!flag)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
