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

int n;
int f, b;

int main() {
	std::cin >> n;
	f = n;
	b = n;
	std::string str, r;
	while (1) {
		str = std::to_string(b);
		r = str;
		std::reverse(str.begin(), str.end());
		if (r == str)
			break;
		str = std::to_string(f);
		r = str;
		std::reverse(str.begin(), str.end());
		if (r == str)
			break;
		++f;
		--b;
	}
	std::cout << r << std::endl;
	return 0;
}