#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;

int main(void) {
	int n;
	int i = 0;

	cin >> n;
	while(1) {
		int s = n - i;
		int l = n + i;
		stringstream sstr1, sstr2;
		string str1, str2;
		string rev1, rev2;

		sstr1 << s; sstr2 << l;
		sstr1 >> str1; sstr2 >> str2;
		rev1.resize(str1.size()); rev2.resize(str2.size());
		reverse_copy(str1.begin(), str1.end(), rev1.begin());
		reverse_copy(str2.begin(), str2.end(), rev2.begin());

		if(str1 == rev1) {
			cout << s << endl;
			break;
		}

		if(str2 == rev2) {
			cout << l << endl;
			break;
		}
		i++;
	}

	return 0;
}