#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = min(s1.size(), s2.size()); i > 0; --i) {
    vector<int> v1(26), v2(26);
    for (int j = 0; j < 26; ++j) v1[j] =v2[j] = 0;
    set<vector<int>> m;
    for (int j = 0; j < i; ++j) ++v1[s1[j] - 'a'];
    for (int j = 0; i + j <= (int)s1.size(); ++j) {
      m.insert(v1);
      --v1[s1[j] - 'a'];
      if (i + j != (int)s1.size()) ++v1[s1[i + j] - 'a'];
    }
    for (int j = 0; j < i; ++j) ++v2[s2[j] - 'a'];
    for (int j = 0; i + j <= (int)s2.size(); ++j) {
      if (m.count(v2)) {
        cout << i << endl;
        return 0;
      }
      --v2[s2[j] - 'a'];
      if (i + j != (int)s2.size()) ++v2[s2[i + j] - 'a'];
    }
  }
  cout << 0 << endl;
}