#include <bits/stdc++.h>
using namespace std;

#define MAXN 4001

typedef unsigned long long ll;
typedef ll Hash;

const ll primes[] = {(ll) 1e18+7, 1000*1000*1000 + 9};
ll power[2][26];

ll mpow(ll a, int n, ll mod) {
	if(n == 0) return 1;
	ll x = mpow(a, n/2, mod);
	x *= x; x %= mod;
	if(n % 2 == 1) x *= a;
	return x % mod;
}

void inc(Hash& h, int pos) {
	h += power[0][pos];
	if(h >= primes[0]) h -= primes[0];
	//$ h.first %= primes[0];
	//$ h.second += power[1][pos];
	//$ if(h.second >= primes[1]) h.second -= primes[1];
	//$ h.second %= primes[1];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 26; j++) 
			power[i][j] = mpow(MAXN, j, primes[i]);
	
	string s, t;
	cin >> s >> t;
	int n = s.length(), m = t.length();
	if(n > m) swap(s, t), swap(n, m);
	unordered_map<Hash, int> sub;
	
	for(int L = 0; L < n; L++) {
		Hash h = 0;
		for(int R = L; R < min(L + 100, n); R++) {
			inc(h, s[R] - 'a');
			sub[h] = R - L + 1;
		}
	}
	
	int ans = 0;
	for(int L = 0; L < m; L++) {
		Hash h = 0;
		for(int R = L; R < min(L + 100, m); R++) {
			inc(h, t[R] - 'a');
			if(sub.count(h)) {
				ans = max(ans,  R - L + 1);
			}
		}
	}
	
	cout << ans << endl;
}

