#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int main() {
    ll N;
    cin >> N;
    int cnt = 0;
    for (int i = 1; i <= 1000000; i++) {
        ll num = i;
        ll cp = i;
        ll t = 1;
        while (cp != 0) {
            t *= 10;
            cp /= 10;
        }
        num = t * (ll)i + (ll)i;
        if (num <= N) cnt++;
    }
    cout << cnt << endl;
}
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<map>
#include<queue>
#include<stack>
#include<set>

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define LL_INF 1e18+5
#define INT_INF 1e9+5
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define LL_INF 1e18+5
#define INT_INF 1e9+5

int main(){
    ll N; cin >> N;
    int cnt = 0;
    ll tmp = 1;
    while(tmp < N){
        cnt++;
        tmp *= 10;
    }
    if(cnt%2 == 1){
        cnt /= 2;
        ll ans = 1;
        while(cnt > 0){
            cnt--;
            ans *= 10;
        }
        cout << ans - 1 << endl;
        return 0;
    }
    else {
        cnt /= 2;
        ll ans = 1;
        while(cnt>0){
            ans *= 10;
            cnt--;
        }
        if(N/ans <= N%ans){
            cout << N/ans << endl;
            return 0;
        }
        else {
            cout << N/ans -1 << endl;
            return 0;
        }
    }
}