#include<bits/stdc++.h>
#define qc ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rt return
#define fi first
#define se second
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
typedef long long ll;
using namespace std;
ll dig(ll n)
{
    ll ans=0;
    while(n>0){
        n/=10;ans++;
    }rt ans;
}
ll ten(ll n)
{
    ll ans=1;
    while(n--){
        ans*=10;
    }
    rt ans;
}
int main(){
    qc
    ll n;cin>>n;
    ll d=dig(n);
    if(d==1)cout<<0;
    else if(d%2==1){
        d/=2;
        for(ll i=0;i<d;i++){
            cout<<9;
        }
    }
    else{
        ll a=n/ten(d/2);
        n%=ten(d/2);
        if(a>n)cout<<a-1;
        else cout<<a;
    }
    rt 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
	ll n;
	cin >> n;
	ll limit = (log10(n)+1)/2;
	ll ans = n/pow(10,limit);
	//cout << ans << " " << limit <<" " << endl;
	ll temp = ans;
	while(temp*pow(10,limit)+temp>n){
		temp--;
		ans--;
		limit = log10(temp)+1;
	}
	cout << ans << endl;
	
	
	return 0;
}