#include <iostream>

bool isPalindromic[10002];
int A[10002], B[10002];

int main(){
    for(int i=0;i<=10001;i++){
        std::string s = std::to_string(i);
        bool f = true;
        for(int j=0;j<s.size();j++){
            if(s[j] != s[s.size()-1-j]){f = false; break;}
        }
        if(f){isPalindromic[i] = true;}
    }
    
    int prev;
    for(int i=0;i<=10001;i++){
        if(isPalindromic[i]){prev = i;}
        A[i] = prev;
    }

    for(int i=10001;i>=0;i--){
        if(isPalindromic[i]){prev = i;}
        B[i] = prev;
    }
    
    int N;
    std::cin >> N;

    if(std::abs(N-A[N]) <= std::abs(N-B[N])){
        std::cout << A[N]<< std::endl;
    }else{
        std::cout << B[N]<< std::endl;
    }
    
}