#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int input;
string toString(int n){stringstream ss; ss << n; return ss.str();}
bool isPalindromicNum(int x){
  string s = toString(x);
  string _s = s;
  reverse(s.begin(), s.end());
  return s == _s;
}
void solve(){
  int margin = input;
  int ans;
  for(int i = 0 ; i < input + margin; i++){
    if(i % 10 == 0)continue;
    if(isPalindromicNum(i)){
      margin = abs(input - i);
      ans = i;
    }
  }
  cout << ans << endl;
}
int main(){
  while(cin >> input){
    solve();
  }
  return 0;
}