#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
string S1, S2;
int f() {
	for (int n = min<int>(S1.length(), S2.length()); n >= 1; --n) {
		vector<int> a1(26), a2(26);
		set<vector<int>> s1;
		for (int i = 0; i < n; ++i) {
			++a1[S1[i] - 'a'];
			++a2[S2[i] - 'a'];
		}
		s1.insert(a1);
		for (int i = n; i < S1.length(); ++i) {
			--a1[S1[i - n] - 'a'];
			++a1[S1[i] - 'a'];
			s1.insert(a1);
		}
		if (s1.count(a2)) {
			return n;
		}
		for (int i = n; i < S2.length(); ++i) {
			--a2[S2[i - n] - 'a'];
			++a2[S2[i] - 'a'];
			if (s1.count(a2)) {
				return n;
			}
		}
	}
	return 0;
}
int main() {
	cin >> S1 >> S2;
	cout << f() << endl;
}
