#include <bits/stdc++.h>
using namespace std;
const int siz = 2e5 + 9;
const int MOD = 1e9 + 7;
int Ans;
string s, t;
map<char, int> mp1, mp2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) mp1[s[i]]++;
  for (int i = 0; i < t.size(); ++i) mp2[t[i]]++;
  for (auto it : mp2) {
    char c = it.first;
    if (!mp1[c]) return cout << -1, 0;
  }
  for (auto it : mp1) {
    char c = it.first;
    Ans += min(it.second, mp2[c]);
    it.second = mp2[c] = 0;
  }
  for (auto it : mp2) {
    char c = it.first;
    Ans += min(it.second, mp1[c]);
    it.second = mp1[c] = 0;
  }
  if (!Ans) return cout << -1, 0;
  cout << Ans;
  return 0;
}
