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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

typedef unsigned long long ull;
const ull p=1000000007;
string S,T;

signed main(){
    ull power[26];
    power[0]=1;
    for(int i=1;i<26;i++)power[i]=power[i-1]*p;

    cin>>S>>T;
    vector<ull>hs;
    for(int i=min(S.size(),T.size());i>0;i--){
        ull h=0;
        hs.clear();
        for(int j=0;j+1<i;j++){
            h+=power[T[j]-'a'];
        }
        for(int j=i-1;j<T.size();j++){
            h+=power[T[j]-'a'];
            hs.pb(h);
            h-=power[T[j-i+1]-'a'];
        }

        sort(all(hs));

        h=0;
        for(int j=0;j+1<i;j++){
            h+=power[S[j]-'a'];
        }
        for(int j=i-1;j<S.size();j++){
            h+=power[S[j]-'a'];
            if(binary_search(all(hs),h)){
                cout<<i<<endl;
                return 0;
            }
            h-=power[S[j-i+1]-'a'];
        }
    }
    cout<<0<<endl;
    return 0;
}