object Main{
  def main(args:Array[String]):Unit={
    var input = readLine
    var record:Map[Int,Int] = Map()
    for(i <- input){
      var tmp = i.toString.toInt
      var r = record.getOrElse(tmp,0)
      r+=1
      record+=(tmp -> r)
    }
    var keys = record.keySet.toArray.sorted.reverse
    var flag = true
    var res = ""
    if(keys.length==1){
      res = input
      flag = false
    }
    for(k <- 0 until keys.length if flag){
      if(k==0 && input.charAt(0).toString.toInt==keys(k)){
        for(i <- 0 until 3) res += keys(0).toString
        flag = false
      }
      if(keys(k)==input.charAt(0).toString.toInt && flag){
        for(i <- 0 until 3) res += keys(k-1).toString
        flag = false
      }
    }
    println(res)

  }
}