#include<iostream>
#include<sstream>
using namespace std;
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

bool chack(int n)
{
  if(n<10)
    return true;
  string tmp=toString(n);
  bool c = true;
  for(int i=0,j=tmp.size()-1;i<=j;i++,j--)
    {
      if(tmp[i]!=tmp[j])
	c=false;
    }
  return c;
}
int main()
{
  int n;
  for(;cin>>n;)
    {
      bool f1=false,f2=false;
      int n1=n,n2=n;
      for(;!(f1||f2);)
	{
	  f1=chack(n1);
	  if(!f1)
	    f2=chack(n2);
	  if(f1)
	    cout<<n1<<endl;
	  else if(f2)
	    cout<<n2<<endl;
	  n1--;
	  n2++;
	}
    }
}