#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int a[1000], b[1000];
int used[1000];
int ans;
int main() {
  cin >> s1;
  for (int i = 0; i < s1.size(); ++i) a[s1[i] - 'a']++;
  cin >> s2;
  for (int i = 0; i < s2.size(); ++i) b[s2[i] - 'a']++;
  for (int i = 0; i < s2.size(); ++i) {
    if (!a[s2[i] - 'a']) {
      cout << "-1" << endl;
      return 0;
    }
    if (!used[s2[i] - 'a']) ans += min(a[s2[i] - 'a'], b[s2[i] - 'a']);
    used[s2[i] - 'a'] = 1;
  }
  cout << ans << endl;
}
