object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val n = readLine.trim
  println(search(n))
  def search(number: String): Int = {
    def toPalindrone(number: String, digit: Int): Int = {
      (number + number.reverse.takeRight(digit - number.length)).toInt
    }
    List(toPalindrone(number.dropRight(number.length / 2), number.length),
      toPalindrone((number.dropRight(number.length / 2).toInt + 1).toString,number.length),
      toPalindrone((number.dropRight(number.length / 2).toInt - 1).toString, number.length)).sorted.minBy(i ⇒ math.abs(i - number.toInt))
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
