#include <bits/stdc++.h>
using namespace std;
int pow(int d) { return d * d; }
int main() {
  ios::sync_with_stdio(false);
  const int N = 26;
  string line;
  int h[N] = {};
  int c[N] = {};
  int v, out = 0;
  cin >> line;
  for (v = 0; v < line.length(); v++) h[line[v] - 'a']++;
  cin >> line;
  for (v = 0; v < line.length(); v++) c[line[v] - 'a']++;
  for (v = 0; v < N; v++) {
    if (c[v] == 0) continue;
    if (h[v] == 0) break;
    out += min(h[v], c[v]);
  }
  cout << (v == N ? out : -1) << endl;
  return 0;
}
