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

typedef long long ll;
string s1,s2;

unordered_set<ll> S;


ll B = 107097077;
ll getHash( const vector<int>& v ){
  ll x = 0;
  for(int i=0;i<26;i++)
    x = x*B+v[i];
  return x;
}

vector<int> v[4444],w[4444];

int main() {
  cin >> s1 >> s2;
  int n = max(s1.size(),s2.size());
  for(int i=0;i<n;i++) v[i] = w[i] = vector<int>(26,0);
  int res = 0;
  for(int k=0;k<n;k++){
    S.clear();
    for(int i=0;i<s1.size();i++){
      int j = i+k;
      if( j >= s1.size() ) continue;
      v[i][ s1[j]-'a' ]++;
      S.insert( getHash(v[i]) );
    }
    for(int i=0;i<s2.size();i++){
      int j = i+k;
      if( j >= s2.size() ) continue;
      w[i][ s2[j]-'a' ]++;
      if( S.count( getHash(w[i] ) ) ) res = k+1;
    }
  }

  cout << res << endl;
  return 0;
}