#include<iostream>
using namespace std;
int main(){

    int siz = 0;
    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        int x = n-i;
        for(int q = 0;q<2;q++){
            //cout<<x<<endl;
            if(x<10)siz = 1;
            else if(x<100)siz = 2;
            else if(x<1000)siz = 3;
            else if(x<10000)siz = 4;
            else siz==5;
            if(siz==1){
                cout<<x<<endl;
                goto end;
            }
            if(siz==2){
                if(x/10==x%10){
                    cout<<x<<endl;
                    goto end;
                }
            }
            else if(siz==3){
                if(x/100==x%10){
                    cout<<x<<endl;
                    goto end;
                }
            }
            else if(siz==4){
                if((x%1000)/100==(x%100)/10&&x/1000==x%10){
                    cout<<x<<endl;
                    goto end;
                }
            }
            else if(siz==5){
                if((x%10000)/1000==(x%100)/10&&x/10000==x%10){
                    cout<<x<<endl;
                    goto end;
                }
            }
            x = n+i;
        }
    }
    end:

    return 0;
}