#!/usr/bin/ruby                                                                                                                               
# -*- coding: utf-8 -*-                                                                                                                       


def isPalindromic(s)
  if s == s.reverse
    return true
  else
    return false
  end
end

s = gets.chomp
i = 0
while true
  tmp = (s.to_i - i).to_s
  if isPalindromic tmp
    puts tmp
    break
  end
  tmp = (s.to_i + i).to_s
  if isPalindromic tmp
    puts tmp
    break
  end
  i += 1
end