#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e5 + 5;
long long int arr[MAXN], n, M = 10000003;
void solve() {
  int sum = 0;
  string a, b;
  cin >> a >> b;
  set<char> second;
  map<char, int> m1, m2;
  for (auto i : a) {
    second.insert(i);
    m1[i]++;
  }
  for (auto i : b) {
    second.insert(i);
    m2[i]++;
  }
  for (auto i : second) {
    if (m1[i] == 0) {
      cout << -1;
      return;
    }
    if (m1[i] >= m2[i]) {
      sum += m2[i];
    } else {
      sum += m1[i];
    }
  }
  cout << sum << endl;
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
