
#include <array>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1,0,1,0 }; const int dy[] = { 0,1,0,-1 };

int main() {
	string s1, s2;
	cin >> s1 >> s2;
	int ans = 0;
	FOR(i, 1, min(s1.size(), s2.size()) + 1) {
		set<array<int,26>> alp;
		array<int, 26> now;
		now.fill(0);
		REP(j, s1.size() - i + 1) {
			if (j == 0) {
				REP(k, i) {
					now[s1[k] -'a']++;
				}
			}
			else {
				now[s1[j+i-1] - 'a']++;
				now[s1[j-1] - 'a']--;
			}
			alp.insert(now);
		}
		now.fill(0);
		REP(j, s2.size() - i + 1) {
			if (j == 0) {
				REP(k, i) {
					now[s2[k] - 'a']++;
				}
			}
			else {
				now[s2[j + i-1] - 'a']++;
				now[s2[j - 1] - 'a']--;
			}
			if (alp.find(now) != alp.end()) {
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}