#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
const int mx = 1e2, mod = 1e6 + 3;
int n, a[mx];
string second, t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> second >> t;
  int sCnt[26] = {}, tCnt[26] = {};
  for (const char &c : second) ++sCnt[c - 'a'];
  for (const char &c : t) ++tCnt[c - 'a'];
  int res = 0;
  for (int i = 0; i < 26; ++i) {
    if (tCnt[i] == 0) continue;
    if (sCnt[i] == 0) {
      cout << "-1\n";
      return 0;
    }
    res += min(tCnt[i], sCnt[i]);
  }
  cout << res << '\n';
}
