#include <bits/stdc++.h>

#define ll long long
#define llong long long
#define REP(i,n) for(auto i=0;i<n;++i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back

using namespace std;

bool isKaibun(string s){
  int len = s.length();
  REP(i,len / 2){
    if(s[i] != s[len - i - 1]){
      return false;
    }
  }
  return true;
}

int main(){

  int n;
  cin >> n;
 
  if(isKaibun(to_string(n))){
    cout << n << endl;
    return 0;
  }

  int i = 1;
  bool f = false;
  while(true){
    string plus = to_string(n + i), minus = to_string(n - i);
    if(isKaibun(minus)){
      cout << minus << endl;
      f = true;
    }else if(isKaibun(plus)){
      cout << plus << endl;
      f = true;
    }
    if(f) break;
    i++;
  }

  return 0;
}

