#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

template<typename T>
struct edge {
    int src, to;
    T cost;
};

template<typename T>
using Graph = vector<vector<edge<T>>>;

using State = string::const_iterator;

struct RollingHash {
    using uint = uint64_t;

    /**
    * @brief コンストラクタ. O(|s|)
    * @param[in] s ハッシュ化する文字列(or vector).
    * @param[in] base ハッシュ化に使う基数. RollingHash::gen_base で作る.
    * @details 使い方
    *   auto base = RollingHash::gen_base();
    *
    *   string t; cin >> t;
    *   RollingHash hash(t, base);
    */
    template<typename S>
    RollingHash(const S& s, uint base) {
        int n = s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash[i+1] = mod(mul(hash[i], base) + s[i]);
            pow[i+1] = mul(pow[i], base);
        }
    }

    /**
    * @brief ハッシュを計算する. O(1)
    * @param[in] l, r ハッシュを計算したい区間.
    * @return 区間[l, r) のハッシュ.
    * @details 使い方
    *   cout << hash.get(0, t.size()) << endl;
    */
    uint get(int l, int r) const {
        return mod(hash[r] + MASK61 - mul(hash[l], pow[r - l]));
    }

    /**
    * @brief 基数を生成する. O(1)
    * @return ランダムな基数.
    * @details 使い方
    *   auto base = RollingHash::gen_base();
    */
    static uint gen_base() {
        mt19937 random{random_device{}()};
        uniform_int_distribution<uint> dist(2, MASK61-2);
        return dist(random);
    }

private:
    vector<uint> hash, pow;
    static const uint MASK30 = (1LL<<30)-1,
            MASK31 = (1LL<<31)-1,
            MASK61 = (1LL<<61)-1;

    static uint mul(uint a, uint b) {
        uint au = a >> 31, ad = a & MASK31,
                bu = b >> 31, bd = b & MASK31;
        uint m = au * bd + ad * bu;
        uint mu = m >> 30, md = m & MASK30;

        return mod(au*bu*2 + mu + (md<<31) + ad*bd);
    }
    static uint mod(uint x) {
        uint xu = x >> 61, xd = x & MASK61;
        uint ret = xu + xd;
        if (ret >= MASK61) ret -= MASK61;
        return ret;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    string s1, s2; cin >> s1 >> s2;
    if (s1.size() > s2.size()) swap(s1, s2);

    using Data = array<int,26>;
    vector<Data> sum1(s1.size()+1), sum2(s2.size()+1);
    REP(i, s1.size()) {
        sum1[i+1] = sum1[i];
        ++sum1[i+1][s1[i] - 'a'];
    }
    REP(i, s2.size()) {
        sum2[i+1] = sum2[i];
        ++sum2[i+1][s2[i] - 'a'];
    }

    using uint = RollingHash::uint;
    const uint base = RollingHash::gen_base();
    int ans = 0;
    REP(len, s1.size()+1) {
        map<uint,bool> mp;
        for (int i = 0; i + len <= s1.size(); ++i) {
            Data diff;
            REP(k, 26) diff[k] = sum1[i + len][k] - sum1[i][k];
            uint hash = RollingHash(diff, base).get(0, 26);
            mp[hash] = 1;
        }
        for (int i = 0; i + len <= s2.size(); ++i) {
            Data diff;
            REP(k, 26) diff[k] = sum2[i + len][k] - sum2[i][k];
            uint hash = RollingHash(diff, base).get(0, 26);
            if (mp.count(hash)) {
                chmax(ans, len);
            }
        }
    }

    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 3948