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