#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int c1[26][4001],c2[26][4001];
int main() {
	string s, t; cin >> s >> t;
	int n1 = s.length(), n2 = t.length();
	rep(i, n1) {
		rep(j, 26) {
			if (s[i] == 'a' + j)c1[j][i+1] = c1[j][i] + 1;
			else c1[j][i+1] = c1[j][i];
		}
	}
	rep(i, n2) {
		rep(j, 26) {
			if (t[i] == 'a' + j)c2[j][i+1] = c2[j][i] + 1;
			else c2[j][i+1] = c2[j][i];
		}
	}
	int out = 0;
	rep1(i, min(n1, n2)) {
		map<vector<int>, bool> mp;
		rep(j, n2 - i + 1) {
			vector<int> v(26);
			rep(k, 26) {
				v[k] = c2[k][j + i] - c2[k][j];
			}
			mp[v] = 1;
		}
		rep(j, n1 - i + 1) {
			vector<int> v(26);
			rep(k, 26) {
				v[k] = c1[k][j + i] - c1[k][j];
			}
			if (mp[v]) {
				out = i; break;
			}
		}
	}
	cout << out << endl;
	return 0;
}
