#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;

int Solve()
{
    int n, n1, n2;
    cin >> n;
    n1 = n2 = n;

    while (n1 != 0) {
        string s = to_string(n1);
        string t = s;
        reverse(t.begin(), t.end());

        if (s == t)
            break;
        --n1;
    }
    while (true) {
        string s = to_string(n2);
        string t = s;
        reverse(t.begin(), t.end());

        if (s == t)
            break;
        ++n2;
    }

    if (abs(n - n1) <= abs(n - n2))
        return n1;
    else
        return n2;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cout << Solve() << endl;

    return 0;
}