#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  string s1, s2;
  cin >> s1 >> s2;
  long long int i;
  map<long long int, long long int> m1, m2;
  for (i = 0; i < s1.size(); i++) {
    m1[s1[i] - 'a']++;
  }
  long long int f = 0;
  for (i = 0; i < s2.size(); i++) {
    m2[s2[i] - 'a']++;
  }
  long long int sum = 0;
  for (i = 0; i < 26; i++) {
    if (m1[i] == 0 && m2[i] != 0) {
      f = 1;
      break;
    }
    if (m1[i] < m2[i]) {
      sum = sum + m1[i];
    } else {
      sum = sum + m2[i];
    }
  }
  if (f) {
    cout << -1;
  } else {
    cout << sum;
  }
}
