#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pcc = pair<char, char>;
using pdd = pair<double, double>;
using pci = pair<char, int>;
using si = set<int>;
using s = string;
using seti = set<int>;
using useti = unordered_set<int>;
using mseti = multiset<int>;
using umseti = unordered_multiset<int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vd = vector<double>;
using vll = vector<ll>;
using vpii = vector<pii>;
using msi = map<string, int>;
using mii = map<int, int>;
using mci = map<char, int>;
using umsi = unordered_map<string, int>;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
const int inf = 1e9 + 9;
const ll INF = 1e18;
const double pi = 3.141592653589793;
void solve() {
  string str1, str2;
  cin >> str1 >> str2;
  int l1 = str1.size();
  int l2 = str2.size();
  mci mp1;
  mci mp2;
  for (int i = 0; i < l1; i++) {
    mp1[str1[i]]++;
  }
  for (int i = 0; i < l2; i++) {
    mp2[str2[i]]++;
  }
  for (int i = 0; i < l2; i++) {
    if (mp1[str2[i]] == 0) {
      cout << "-1" << endl;
      return;
    }
  }
  int sum = 0;
  for (auto it = mp2.begin(); it != mp2.end(); it++) {
    char temp = it->first;
    int l1, l2;
    l1 = mp1[temp];
    l2 = mp2[temp];
    if (l1 >= l2) {
      sum += l2;
    } else {
      sum += l1;
    }
  }
  cout << sum << endl;
  return;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
  return 0;
}
