#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

int intrev(int n){
	int ret = 0;
	while(n > 0){
		ret *= 10;
		ret += n%10;
		n /= 10;
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	int d = 10000, ans = -1;
	for(int i = 0; i < 10000; i++){
		if(i != intrev(i)) continue;
		if(d > abs(n-i)){
			d = abs(n-i);
			ans = i;
		}
	}
	cout << ans << endl;

	return 0;
}