palindrome = Array.new
for i in 1..10000 do
  digit = i.to_s.chars.map(&:to_i)
  ok = true
  while(digit.size > 1) do
    ok = false if digit.shift != digit.pop
  end
  palindrome.push(i) if ok
end

n = gets.to_i
min = 10000
answer = 0
palindrome.each do |i|
  dif = (n - i).abs
  break if min <= dif
  min = dif
  answer = i
end

p answer