#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ar=array<ull,26>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
int main(){
	string s1,s2;
	ar ht; ht[0]=1;
	rep(i,25) ht[i+1]=ht[i]*10007;
	
	while(cin>>s1>>s2){
		if(s1.size()>s2.size()) swap(s1,s2);
		int n1=s1.size(), n2=s2.size();
		unordered_set<ull> list1;
		vector<ull> p1,p2;
		for(auto c:s1)p1.push_back(ht[c-'a']);
		for(auto c:s2)p2.push_back(ht[c-'a']);
		
		for(int l=n1;l>=1;l--){
			list1.clear();
			ull tmp=0;
			rep(i,n1) {
				tmp+=p1[i];
				if(i>=l) tmp-=p1[i-l];
				if(i>=l-1) list1.insert(tmp);
			}
			tmp=0;
			rep(i,n2){
				tmp+=p2[i];
				if(i>=l) tmp-=p2[i-l];
				if(i>=l-1) {
					if(list1.find(tmp) != list1.end()){
						cout<<l<<endl;
						goto end;
					}
				}
			}
		}
		cout<<0<<endl;
		end: ;
	}
	return 0;
}

