import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val s1 = readLine.trim
  val s2 = readLine.trim
  val countS1 = Array.fill(s1.length + 1){Array.fill(26){0}}
  val countS2 = Array.fill(s2.length + 1){Array.fill(26){0}}
  for (i ← s1.indices; j ← 0 until 26) {countS1(i + 1)(j) = countS1(i)(j) + (if (s1(i) - 'a' == j) 1 else 0)}
  for (i ← s2.indices; j ← 0 until 26) {countS2(i + 1)(j) = countS2(i)(j) + (if (s2(i) - 'a' == j) 1 else 0)}
  println((1 to Math.min(s1.length, s2.length)).reverse.find(len ⇒ canMakeHiddenAnagram(countS1, countS2, len)).getOrElse(0))
  def canMakeHiddenAnagram(str1: Array[Array[Int]], str2: Array[Array[Int]], length: Int): Boolean = {
    val set = mutable.Set[List[Int]]()
    for (from ← 0 until str1.length - length) {
      set += str1(from + length).zip(str1(from)).map{case (a, b) ⇒ a - b}.toList
    }
    (0 until  str2.length - length).exists(from ⇒ set.contains(str2(from + length).zip(str2(from)).map{case (a, b) ⇒ a - b}.toList))
  }
}
