#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<pair<T, T> > &v) {
  for (size_t i = 0; i < v.size(); ++i)
    out << "(" << v[i].first << ", " << v[i].second << ") ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    for (size_t j = 0; j < v[i].size(); ++j) {
      out << v[i][j] << " ";
    }
    out << "\n";
  }
  return out;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string n, m;
  cin >> n >> m;
  int sz1 = n.size();
  int sz2 = m.size();
  vector<int> occs_n(26), occs_m(26);
  for (int i = 0; i < sz1; ++i) {
    ++occs_n[n[i] - 'a'];
  }
  for (int i = 0; i < sz2; ++i) {
    ++occs_m[m[i] - 'a'];
  }
  int area = 0;
  for (int i = 0; i < 26; ++i) {
    if (occs_m[i] && !occs_n[i]) {
      cout << "-1\n";
      return 0;
    }
    area += min(occs_m[i], occs_n[i]);
  }
  cout << area << "\n";
  return 0;
}
