/*************************************************************************
    > File Name: DD.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/7/11 13:15:17
 ************************************************************************/

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

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
const int maxn = 4444;
char s[maxn], t[maxn];
int cnts[33], cntt[33];
int len1, len2;
ll md[] = { 1000000009,1000000007 };
ll key[] = { 1000000007,19260817 };
pii hh(int *a){
    ll ret[2];
    rep(i,0,25){
        rep(j,0,1){
            ret[j]=(ret[j]*key[j]+a[i])%md[j];
        }
    }
    return mp((int)ret[0],(int)ret[1]);
}
set<pii>has;
bool check(int len){
    has.clear();
    cl(cnts);cl(cntt);
    rep(i,1,len){ cnts[s[i]-'a']++; }
    int ls=1,rs=len;
    while(rs<=len1){
        has.insert(hh(cnts));
        cnts[s[ls]-'a']--;ls++;
        rs++;if(rs>len1)break;
        cnts[s[rs]-'a']++;
    }
    rep(i,1,len){ cntt[t[i]-'a']++; }
    int lt=1,rt=len;
    while(rt<=len2){
        pii now = hh(cntt);
        if(has.count(now)){
            return true;
        }
        cntt[t[lt]-'a']--; lt++;
        rt++;if(rt>len2)break;
        cntt[t[rt]-'a']++;
    }
    return false;
}
int main(){
#ifdef HandsomeHow
    freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
#endif
    scanf("%s%s",s+1,t+1);
    len1 = strlen(s+1);
    len2 = strlen(t+1);
    int l = 0, r = min(len1,len2);
    per(i,r,1){
        if(check(i)){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
    return 0;
}