#include <bits/stdc++.h>
std::string s, g;
int r, c, C, G;
int main() {
  std::cin >> s >> g;
  for (c = 'a'; c <= 'z' && r + 1; c++)
    (G = std::count(g.begin(), g.end(), c))
        ? (r = (C = std::count(s.begin(), s.end(), c)) ? r + (G > C ? C : G)
                                                       : -1)
        : 0;
  std::cout << r;
}
