#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	int n;
	char num[5];
	bool isPalindromicNumber;
	cin >> n;

	for(int i=0;; i++){
		isPalindromicNumber = true;
		sprintf(num, "%d", n-i);
		for(int j=0; j < strlen(num); j++){
			if(num[j] != num[strlen(num)-j-1]) isPalindromicNumber = false;
		}
		if(isPalindromicNumber){
			cout << n-i << endl;
			return 0;
		}

		isPalindromicNumber = true;
		sprintf(num, "%d", n+i);
		for(int j=0; j < strlen(num); j++){
			if(num[j] != num[strlen(num)-j-1]) isPalindromicNumber = false;
		}
		if(isPalindromicNumber){
			cout << n+i << endl;
			return 0;
		}
	}
}