#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define int long long
using namespace std;

string s[2];
int cnt[2][4001][26];
vector<vector<int>> dict;

//[l, r)
vector<int> getArray(int type, int l, int r) {
	vector<int> ret(26);
	for (int i = 0; i < 26; i++) {
		ret[i] = cnt[type][r][i] - cnt[type][l][i];
	}
	return ret;
}

signed main() {
	int l, r;
	
	cin >> s[0] >> s[1];
	for (int i = 0; i < s[0].length(); i++) cnt[0][i + 1][s[0][i] - 'a']++;
	for (int i = 0; i < s[1].length(); i++) cnt[1][i + 1][s[1][i] - 'a']++;
	for (int i = 1; i <= s[0].length(); i++) for (int j = 0; j < 26; j++) cnt[0][i][j] += cnt[0][i - 1][j];
	for (int i = 1; i <= s[1].length(); i++) for (int j = 0; j < 26; j++) cnt[1][i][j] += cnt[1][i - 1][j];
	
	for (int length = min(s[0].length(), s[1].length()); length > 0; length--) {
		dict.clear();
		for (l = 0; l < s[1].length(); l++) {
			r = l + length;
			if (r > s[1].length()) break;
			dict.push_back(getArray(1, l, r));
		}
		sort(dict.begin(), dict.end());
		
		for (l = 0; l < s[0].length(); l++) {
			r = l + length;
			if (r > s[0].length()) break;
			
			vector<int> a = getArray(0, l, r);
			if (*lower_bound(dict.begin(), dict.end(), a) == a) {
				cout << length << endl;
				return 0;
			}
		}
	}
	
	cout << 0 << endl;
	return 0;
}