#include <iostream>
#include <vector>
#include <string>
#include <set>

using Bool = bool;
using Int = long long int;
using Char = char;
using String = std::string;
template <class T>
using Vector = std::vector<T>;
template <class T>
using Set = std::set<T>;

int main() {
    String s, t;
    std::cin >> s >> t;

    Vector<Vector<Int>> ssum;
    ssum.reserve(s.length() + 1);

    Vector<Vector<Int>> tsum;
    tsum.reserve(t.length() + 1);

    Vector<Int> acc(26, 0);
    ssum.push_back(acc);
    for (Char c : s) {
        ++acc[c - 'a'];
        ssum.push_back(acc);
    }

    std::fill(acc.begin(), acc.end(), 0);
    tsum.push_back(acc);
    for (Char c : t) {
        ++acc[c - 'a'];
        tsum.push_back(acc);
    }

    Int ans = 0;
    Set<Vector<Int>> ss;
    for (Int l = 0; l <= std::min(s.length(), t.length()); ++l) {
        ss.clear();
        for (Int i = 0; i + l <= s.length(); ++i) {
            for (Int j = 0; j < 26; ++j) {
                acc[j] = ssum[i + l][j] - ssum[i][j];
            }
            ss.insert(acc);
        }

        for (Int i = 0; i + l <= t.length(); ++i) {
            for (Int j = 0; j < 26; ++j) {
                acc[j] = tsum[i + l][j] - tsum[i][j];
            }
            if (ss.count(acc)) ans = l;
        }
    }

    std::cout << ans << std::endl;
    return 0;
}

