#include <cstdio>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main()
{
	int mini = 1145141919;
	int mindif = 1145141919;
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i <= 20000; i++){
		char a[16];
		sprintf(a, "%d", i);
		
		char b[16];
		strcpy(b, a);
		reverse(b, b + strlen(b));
		
		if (strcmp(a, b) == 0){
			if (mindif > abs(n - i)){
				mindif = abs(n - i);
				mini = i;
			}
		}
	}
	
	printf("%d\n", mini);
	
	return 0;
}