#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;

string to_s(int n){
	string s;
	while(n)s+=(char)(n%10+'0'),n/=10;
	return s;
}

bool f(string s){
	string c = s;
	reverse(s.begin(),s.end());
	return c == s;
}

int main(void){
	int n,i=0;
	cin>>n;
	while(true){
		if(f(to_s(n-i))){
			cout<<n-i<<endl;
			break;
		}else if(f(to_s(n+i))){
			cout<<n+i<<endl;
			break;
		}
		i ++;
	}
}