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

int main() {
    string s1, s2;
    cin >> s1 >> s2;

    int mw = min(s1.size(), s2.size());
    int res = 0;
    for(int w=mw; w>0; --w) {
        set<vector<int>> s;
        vector<int> cnt1(26);
        for(int i=0; i<w; ++i) {
            cnt1[s1[i]-'a']++;
        }
        s.insert(cnt1);
        for(int i=1; i+w-1<s1.size(); ++i) {
            cnt1[s1[i-1]-'a']--;
            cnt1[s1[i+w-1]-'a']++;
            s.insert(cnt1);
        }

        bool f = false;
        vector<int> cnt2(26);
        for(int i=0; i<w; ++i) {
            cnt2[s2[i]-'a']++;
        }
        if(s.count(cnt2) == 1) {
            res = w;
            f = true;
        }
        if(f) {
            break;
        }
        for(int i=1; i+w-1<s2.size(); ++i) {
            cnt2[s2[i-1]-'a']--;
            cnt2[s2[i+w-1]-'a']++;
            if(s.count(cnt2) == 1) {
                res = w;
                f = true;
            }
        }
        if(f) {
            break;
        }
    }
    cout << res << endl;
}
