#include<iostream>
#include<algorithm>
#include<string>    
#include<cmath>
using namespace std;

int main(){
    long n,temp,temp1,ans;cin>>n;
    long digit=to_string(n).size();
    if(digit%2==1){
        temp=pow(10,digit/2)-1;
        ans=temp;
    }else{
        temp=n/pow(10,digit/2);
        temp1=n%(long)pow(10,digit/2);
        if(temp>temp1)ans=temp-1;
        else ans=temp;
    }

    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std ;

#define ll              long long 
#define pb              push_back
#define all(v)          v.begin(),v.end()
#define sz(a)           (ll)a.size()
#define F               first
#define S               second
#define INF             2000000000000000000
#define popcount(x)     __builtin_popcountll(x)
#define pll             pair<ll,ll> 
#define pii             pair<int,int>
#define ld              long double

const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}

int _runtimeTerror_()
{
    string n;
    cin>>n;
    if(sz(n) <= 1)
    {
        cout<<"0\n";return 0;
    }
    if(sz(n)%2 != 0)
    {
        int u = (sz(n))/2;
        cout<<power(10,u)-1<<"\n";
        return 0;
    }
    ll x = 0;
    string t;
    for(int i=0;i<sz(n)/2;++i)
    {
        x += (n[i]-'0')*power(10,sz(n)/2-i-1);
        t += n[i];
    }
    t += t;
    if(t > n)
        --x;
    cout<<x<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}