#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s[2];
vector<vector<int>> cnt[2];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s[0] >> s[1];
  for (int i = 0; i < 2; i++) {
    cnt[i].resize(4010, vector<int>(26, 0)); 
    for (int j = 0; j < s[i].size(); j++) {
      cnt[i][j+1] = cnt[i][j];
      cnt[i][j+1][s[i][j]-'a']++;
    }
  }
  for (int d = min(s[0].size(), s[1].size()); d >= 1; d--) {
    map<vector<int>, int> mp;
    for (int i = d; i <= s[0].size(); i++) {
      vector<int> tmp = cnt[0][i];
      for (int j = 0; j < 26; j++) {
        tmp[j] -= cnt[0][i-d][j];
      }
      mp[tmp]++;
    }
    for (int i = d; i <= s[1].size(); i++) {
      vector<int> tmp = cnt[1][i];
      for (int j = 0; j < 26; j++) {
        tmp[j] -= cnt[1][i-d][j];
      }
      if (mp[tmp]) {
        cout << d << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;

  return 0;
}
