// editor3
import java.util.*;

public class Main {
    // Helper: check palindrome
    private static boolean isPalindrome(String s) {
        int i = 0, j = s.length() - 1;
        while (i < j) {
            if (s.charAt(i) != s.charAt(j)) return false;
            i++;
            j--;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine().trim();

        // Validate input
        if (n == null || n.isEmpty() || n.length() > 18 || !n.matches("\\d+")) {
            System.out.println("Invalid input");
            return;
        }

        long num = Long.parseLong(n);

        long lower = num - 1;
        while (lower >= 0 && !isPalindrome(Long.toString(lower))) {
            lower--;
        }

        long higher = num + 1;
        while (!isPalindrome(Long.toString(higher))) {
            higher++;
        }

        // Compare which is closer
        if (lower < 0 || (higher - num) < (num - lower)) {
            System.out.println(higher);
        } else if ((higher - num) > (num - lower)) {
            System.out.println(lower);
        } else {
            // If equal distance → choose smaller
            System.out.println(Math.min(lower, higher));
        }
    }
}
