#include <iostream>
using namespace std;

bool kansu( long long int n ) {

  if ( n < 0 ) return false;

  long long int m = n;
  char c[5];
  long long int k;
  for ( k = 0; m != 0; k++ ) {
    c[k] = m % 10 + '0';
    m /= 10;
  }
  for ( int i = 0; i < k; i++ ) {
    if ( c[i] != c[ k-i-1 ] ) return false;
  }
  return true;

}

int main() {

  long long int n;
  cin >> n;

  for ( int i = 0; true; i++ ) {

    if ( kansu( n - i ) == true ) {
      cout << n - i << endl;
      break;
    }
    if ( kansu( n + i ) == true ) {
      cout << n + i << endl;
      break;
    }

  }

  return 0;

}