#include <bits/stdc++.h>
using namespace std;
using ll = __int128;
const ll b = 1713302033171ll;

ll Pow(ll x, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) {
			res = (res * x) % b;
		}
		x = (x * x) % b;
		n >>= 1;
	}
	return res;
}

int main()
{
	vector<ll> prime;
	for (ll i = 100000;prime.size() < 26; i++) {
		bool flag = true;
		for (ll j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			prime.push_back(i);
		}
	}

	string s1, s2;
	cin >> s1 >> s2;
	int n1 = s1.size(), n2 = s2.size();
	vector<ll> rh1(n1 + 1), rrh1(n1 + 1), rh2(n2 + 1), rrh2(n2 + 1);
	rh1[0] = rrh1[0] = rh2[0] = rrh2[0] = 1;
	for (int i = 1; i <= n1; i++) {
		rh1[i] = (rh1[i - 1] * prime[s1[i - 1] - 'a']) % b;
		rrh1[i] = Pow(rh1[i], b - 2);
	}
	for (int i = 1; i <= n2; i++) {
		rh2[i] = (rh2[i - 1] * prime[s2[i - 1] - 'a']) % b;
		rrh2[i] = Pow(rh2[i], b - 2);
	}
	bool fini = true;
	for (int k = min(n1, n2); k > 0; k--) {
		bool can = false;
		vector<ll> hs(n1 - k + 1);
		for (int i = 0; i + k <= n1; i++) {
			hs[i] = (rrh1[i] * rh1[i + k]) % b;
		}
		sort(hs.begin(), hs.end());
		for (int j = 0; j + k <= n2; j++) {
			if (binary_search(hs.begin(), hs.end(), (rrh2[j] * rh2[j + k]) % b)) {
				can = true;
				break;
			}
		}
		if (can) {
			fini = false;
			cout << k << endl;
			break;
		}
	}
	if (fini) {
		cout << 0 << endl;
	}
	return 0;
}