#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <iostream>
#include <string.h>
#include <algorithm>
using  namespace  std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 4000+5;

char s1[N], s2[N];
int n, m;
ull p[30], h1[N][N], h2[N][N];

void calc(int n, ull hx[][N], char *s){
    for(int i=1; i<=n; i++){
        ull h = 0;
        for(int j=i; j<=n; j++)h += p[s[j]-'a'], hx[j-i+1][i] = h;
    }
}

void go(){
    int ans = 0;
    calc(n, h1, s1);
    calc(m, h2, s2);
    int len = min(n, m);
    for(int i=1; i<=n; i++)sort(h1[i]+1, h1[i]+2+n-i);
    for(int i=1; i<=m; i++)sort(h2[i]+1, h2[i]+2+m-i);
    for(int i=1; i<=len; i++){
        for(int j=1; j+i-1<=n; j++){
            int pos = lower_bound(h2[i]+1, h2[i]+2+m-i, h1[i][j])-h2[i];
            if(h2[i][pos] == h1[i][j])ans = max(ans, i);
        }
    }
    printf("%d\n", ans);
}

int  main(){
    scanf("%s%s", s1+1, s2+1);
    n = strlen(s1+1), m = strlen(s2+1);
    p[0] = 1;
    for(int i=1; i<30; i++)p[i] = p[i-1]*233;
    go();
    return 0;
}


// lower_bound()
// __builtin_popcount()
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// const double eps=1e-12;
// #pragma comment(linker,"/STACK:102400000,102400000")