#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    ll N;
    cin >> N;

    // 回文かつ 10^9+1 の倍数であることから、
    // 1 2 3 4 4 3 2 1 0 1 2 3 4 4 3 2 1
    // のようになっている。

    ll ans = 0;
    int cnt = 1, zeros = 8;
    for(ll i = 1000000000LL; i <= min((ll)1e+18 - 1, N); i *= 10){
        if(N / i >= 10){
            ll add = cnt % 2 ? (cnt / 2 ? 10 : 9) : 1;
            for(int j = 0; j < cnt / 2; ++j)    add *= (j ? 10 : 9);
            ans += add;
        }
        else{
            // 自由に決められる値は最大でも 4 桁
            // (dfs が呼び出される回数) <= 10^4
            auto dfs = [&](auto&& self, string s = "") -> void {
                if((int)s.length() == cnt / 2){
                    string t = s;
                    reverse(t.begin(), t.end());
                    if(cnt % 2 == 0){
                        string num = s + t;
                        for(int i = 0; i < zeros; ++i)  num += '0';
                        num += s + t;
                        ans += stoll(num) <= N;
                    }
                    else{
                        for(char ch = (s.length() ? '0' : '1'); ch <= '9'; ++ch){
                            string num = s + ch + t;
                            for(int i = 0; i < zeros; ++i)  num += '0';
                            num += s + ch + t;
                            ans += stoll(num) <= N;
                        }
                    }
                    return;
                }
                for(char ch = (s.length() ? '0' : '1'); ch <= '9'; ++ch){
                    self(self, s + ch);
                }
            };
            dfs(dfs);
        }
        cnt += 1;
        zeros -= 1;
    }
    
    cout << ans << endl;

    return 0;
}