#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

string a, b;
vector<int> cnt;
int n, ans;
map<vector<int>, bool> c;

int main() {
	cin >> a >> b; n = a.size();
	a = '!' + a; b = '!' + b;
	cnt.assign(26, 0);
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j < 26; ++j) cnt[j] = 0;
		for(int j = i; j <= n; ++j) {
			cnt[a[j] - 'a']++;
			c[cnt] = true;
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j < 26; ++j) cnt[j] = 0;
		for(int j = i; j <= n; ++j) {
			cnt[b[j] - 'a']++;
			if(c[cnt]) ans = max(ans, j - i + 1);
		}
	}
	cout << ans;
}