#include <bits/stdc++.h>
using namespace std;
int main() {
  string n, m;
  cin >> n >> m;
  int q[26], a[26];
  for (int i = 0; i < 26; i++) {
    q[i] = 0;
    a[i] = 0;
  }
  for (int i = 0; n[i] != '\0'; i++) {
    q[n[i] - 'a']++;
  }
  for (int i = 0; m[i] != '\0'; i++) {
    a[m[i] - 'a']++;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    if (q[i] == 0 && a[i] != 0) {
      cout << "-1";
      return 0;
    }
    ans = ans + min(q[i], a[i]);
  }
  cout << ans;
  return 0;
}
