//43
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  int x=1;
  for(int i=1;i<=22222;i++){
    if(abs(n-x)>abs(n-i)){
      stringstream ss;
      ss<<i;
      string s;
      ss>>s;
      if(s==string(s.rbegin(),s.rend())){
	x=i;
      }
    }
  }
  cout<<x<<endl;
  return 0;
}