#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int BASE = 4200;
const int MOD = 1e9 + 9;
const int MOD2 = 1e9 + 7;
int pot[26], pot2[26];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    pot[0] = pot2[0] = 1;
    fori(i, 1, 26) {
        pot[i] = (1LL * pot[i - 1] * BASE) % MOD;
        pot2[i] = (1LL * pot2[i - 1] * BASE) % MOD2;
    }
    string a, b;
    cin >> a >> b;
    vector<ii> all;
    fori(i, 0, a.size()) {
        int h = 0, h2 = 0;
        fori(j, i, a.size()) {
            h = (h + pot[a[j] - 'a']) % MOD;
            h2 = (h2 + pot2[a[j] - 'a']) % MOD2;
            all.emplace_back(h, h2);
        }
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    int ans = 0;
    fori(i, 0, b.size()) {
        int h = 0, h2 = 0;
        fori(j, i, b.size()) {
            h = (h + pot[b[j] - 'a']) % MOD;
            h2 = (h2 + pot2[b[j] - 'a']) % MOD2;
            auto it = lower_bound(all.begin(), all.end(), ii(h, h2));
            if(it != all.end() && *it == ii(h, h2)) {
                ans = max(ans, j - i + 1);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

