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

long long p1=1e9+7, p2=1e9+9, p3 =48*1e6+23, alpha1=26,alpha2=37,alpha3=41;
vector<long long>powers1,powers2,powers3;
vector<int>frequency;
vector<bool>bloomFilter1(p1,false);
vector<bool>bloomFilter2(p2,false);
vector<bool>bloomFilter3(p3,false);
long long offset1=p1, offset2=p2, offset3=p3;
void hashPowers(int n){
    long long sum1=0, running1 =1, sum2=0,running2=2, sum3=0,running3=1;
    for(int i=0;i<n;i++){
        sum1=(running1%p1+sum1)%p1;
        sum2=(running2%p2+sum2)%p2;
        sum3=(running3%p3+sum3)%p3;
        running1 = (running1*alpha1)%p1;
        running2 = (running2*alpha2)%p2;
        running3 = (running3*alpha3)%p3;
        powers1.push_back(sum1);
        powers2.push_back(sum2);
        powers3.push_back(sum3);
    }
}
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    // #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL) ; cout.tie(NULL) ;
    int n1, n2, i, j, k;
    string s1, s2;
    cin>>s1>>s2;
    hashPowers(27);
    if(s1.length()>s2.length()){
        string temp=s2;
        s2=s1;
        s1=temp;
    }
    n1=s1.length(),n2=s2.length();
    for(int len=n1;len>0;len--){
        long long runningHash1=0,runningHash2=0;
        for(i=0;i<len;i++){
            runningHash1=(runningHash1+powers1[s1[i]-'a'])%p1;
            runningHash2=(runningHash2+powers2[s1[i]-'a'])%p2;
        }
        bloomFilter1[runningHash1]=true;bloomFilter2[runningHash2]=true;
        for(i=1;i<n1-len+1;i++){
            runningHash1=(runningHash1+powers1[s1[i+len-1]-'a']+p1-powers1[s1[i-1]-'a'])%p1;
            bloomFilter1[runningHash1]=true;
            runningHash2=(runningHash2+powers2[s1[i+len-1]-'a']+p2-powers2[s1[i-1]-'a'])%p2;
            bloomFilter2[runningHash2]=true;
        }
        runningHash1=0;runningHash2=0;
        for(i=0;i<len;i++){
            runningHash1=(runningHash1+powers1[s2[i]-'a'])%p1;
            runningHash2=(runningHash2+powers2[s2[i]-'a'])%p2;
        }
        if(bloomFilter1[runningHash1]&&bloomFilter2[runningHash2]){cout<<len<<endl;return 0;}
        for(i=1;i<n2-len+1;i++){
            runningHash1=(runningHash1-powers1[s2[i-1]-'a']+powers1[s2[i+len-1]-'a']+p1)%p1;
            runningHash2=(runningHash2-powers2[s2[i-1]-'a']+powers2[s2[i+len-1]-'a']+p2)%p2;
            if(bloomFilter1[runningHash1]&&bloomFilter2[runningHash2]){cout<<len<<endl;return 0;}
        }
        runningHash1=0;runningHash2=0;
        for(i=0;i<len;i++){
            runningHash1=(runningHash1+powers1[s1[i]-'a'])%p1;
            runningHash2=(runningHash2+powers2[s1[i]-'a'])%p2;
        }
        bloomFilter1[runningHash1]=false;bloomFilter2[runningHash2]=false;
        for(i=1;i<n1-len+1;i++){
            runningHash1=(runningHash1+powers1[s1[i+len-1]-'a']+p1-powers1[s1[i-1]-'a'])%p1;
            bloomFilter1[runningHash1]=false;
            runningHash2=(runningHash2+powers2[s1[i+len-1]-'a']+p2-powers2[s1[i-1]-'a'])%p2;
            bloomFilter2[runningHash2]=false;
        }
    }
    cout<<0<<endl;
    // for(i=0;i<n1;i++){
    //     long long runningHash1=0, runningHash2=0, runningHash3=0;
    //     for(j=i;j<n1;j++){
    //         if(i==j) {
    //             runningHash1=(offset1+powers1[s1[j]-'a'])%p1;
    //             runningHash2=(offset2+powers2[s1[j]-'a'])%p2;
    //             runningHash3=(offset3+powers3[s1[j]-'a'])%p3;
    //         }
    //         else {
    //             runningHash2=(offset2+runningHash2+powers2[s1[j]-'a'])%p2;
    //             runningHash1=(offset1+runningHash1+powers1[s1[j]-'a'])%p1;
    //             runningHash3=(offset3+runningHash3+powers3[s1[j]-'a'])%p3;
    //         }
    //         bloomFilter1[runningHash1]=true;
    //         bloomFilter2[runningHash2]=true;
    //         bloomFilter3[runningHash3]=true;
    //     }
    // }
    // int ans=0;
    // for(i=0;i<n2;i++){
    //     long long runningHash1=0, runningHash2=0, runningHash3=0;
    //     for(j=i;j<n2;j++){
    //         if(i==j) {
    //             runningHash1=(offset1+powers1[s2[j]-'a'])%p1;
    //             runningHash2=(offset2+powers2[s2[j]-'a'])%p2;
    //             runningHash3=(offset3+powers3[s2[j]-'a'])%p3;
    //         }
    //         else {
    //             runningHash2=(offset2+runningHash2+powers2[s2[j]-'a'])%p2;
    //             runningHash1=(offset1+runningHash1+powers1[s2[j]-'a'])%p1;
    //             runningHash3=(offset3+runningHash3+powers3[s2[j]-'a'])%p3;
    //         }
    //         if(bloomFilter1[runningHash1]&&bloomFilter2[runningHash2]&&bloomFilter3[runningHash3])
    //             ans=max(j-i+1, ans);
    //     }
    // }
    // cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 252696