#include<cstdio>
#include<cstring>
#include<algorithm>

class Solution{
private :
    typedef unsigned long long ull;
    static const int maxn = 4e3 + 7;
    static const int base = 4007;
    static const int mod1 = 1e9 + 7;
    static const int mod2 = 1e9 + 9;
    
    int n, ans, cnt;
    ull pow1[30], pow2[30], b[maxn * maxn];
    char s1[maxn], s2[maxn];
    //std::map<ull, bool> vis;
    
public :
    Solution() {
        Get();
        Solve();
    }

    void Get() {
        scanf("%s", s1 + 1);
        scanf("%s", s2 + 1);
    }

    void Solve() {
        pow1[0] = pow2[0] = 1;
        for (register int i = 1; i <= 27; i++) {
            pow1[i] = pow1[i - 1] * base % mod1;
            pow2[i] = pow2[i - 1] * base % mod2;
        }
        n = strlen(s1 + 1);
        for (register int i = 1; i <= n; i++) {
            ull hash1 = 0, hash2 = 0;
            for (register int j = i; j <= n; j++) {
                //- sum[x] * pow
                //sum[x]++
                //+ sum[x] * pow
                hash1 = (hash1 + pow1[s1[j] - 'a']) % mod1;
                hash2 = (hash2 + pow2[s1[j] - 'a']) % mod2;
                //vis[hash1 * mod2 + hash2] = 1;
                b[++cnt] = hash1 * mod2 + hash2;
            }
        }
        std::sort(b + 1, b + 1 + cnt);
        n = strlen(s2 + 1);
        for (register int i = 1; i <= n; i++) {
            ull hash1 = 0, hash2 = 0;
            for (register int j = i; j <= n; j++) {
                hash1 = (hash1 + pow1[s2[j] - 'a']) % mod1;
                hash2 = (hash2 + pow2[s2[j] - 'a']) % mod2;
                int pos = std::lower_bound(b + 1, b + 1 + cnt, hash1 * mod2 + hash2) - b;
                if (b[pos] == hash1 * mod2 + hash2) {
                    ans = std::max(ans, j - i + 1);
                }
            }
        }
        printf("%d\n", ans);
    }
};
Solution sol;

int main() {}

