#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int main(){

	int N,upper_Pal,down_Pal,length,tmp,work;
	queue<int> Q;

	scanf("%d",&N);

	for(int num = N; num >= 0; num--){
		tmp = num;
		for(length = 0; tmp > 0; length++){
			Q.push(tmp%10);
			tmp /= 10;
		}

		work = 0;
		for(int k = 1; k <= length; k++){
			work += Q.front()*pow(10,length-k);
			Q.pop();
		}

		if(work == num){
			down_Pal = num;
			break;
		}
	}

	for(int num = N+1; num <= 10001; num++){
		tmp = num;
		for(length = 0; tmp > 0; length++){
			Q.push(tmp%10);
			tmp /= 10;
		}

		work = 0;
		for(int k = 1; k <= length; k++){
			work += Q.front()*pow(10,length-k);
			Q.pop();
		}

		if(work == num){
			upper_Pal = num;
			break;
		}
	}

	if(abs(upper_Pal - N) < abs(down_Pal-N)){
		printf("%d\n",upper_Pal);
	}else{
		printf("%d\n",down_Pal);
	}

	return 0;
}