n = int(input()) def is_palindrome(x): s = str(x) return s == s[::-1] for i in range(n, 0, -1): if is_palindrome(i): print(i) break