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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S, T;
  cin >> S >> T;
  int N = SZ(S), M = SZ(T);

  int ans = 0;
  for(int l=1;l<=min(N,M);++l){
	set<VI> memo;
	VI tmp(26);
	REP(i,l) tmp[S[i]-'a']++;
	memo.insert(tmp);
	for(int b=0,e=l;e<N;++b,++e){
	  tmp[S[b]-'a']--;
	  tmp[S[e]-'a']++;
	  memo.insert(tmp);
	}

	tmp.assign(26,0);
	REP(i,l) tmp[T[i]-'a']++;
	if(memo.count(tmp)){
	  ans = l;
	  continue;
	}
	for(int b=0,e=l;e<M;++b,++e){
	  tmp[T[b]-'a']--;
	  tmp[T[e]-'a']++;
	  if(memo.count(tmp)){
		ans = l;
		break;
	  }
	}
  }
  cout << ans << endl;
  
  return 0;
}