#include<iostream>
using namespace std;
#define ll long long
ll pos(int a){
	ll sum=1;
	for(int i=1;i<=a;i++){
		sum*=10;
	}
	return sum;
}
ll pp(int n){
	ll sum=0;
	for(int i=1;i<=n;i++){
		sum=sum*10+9;
	}
	return sum;
}
int main()
{
	
	ll n;
	cin>>n;
	ll  temp=n;
	int digit=0;
	while(temp){
		temp/=10;
		digit++;
	}
	if(digit%2==0){
		digit/=2;
		ll num=pos(digit);
		ll t1=n%num;//hou
		ll t2=n/num;//qian 
		if(t2>t1) cout<<t2-1;
		else cout<<t2;
		return 0;
	}
	else{
		digit=digit/2;
		ll num=pp(digit);
		cout<<num<<endl;
	}
	return 0;
 } 
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    string s;
    cin >> s;
    int nn = s.length();
    int i2 = 9;
    int i4 = 90;
    int i6 = 900;
    int i8 = 9000;
    int i10 = 90000;
    if(nn <= 1){
    	cout<<0;
        return 0;
    }
    else if(nn <= 2){
        long long a = stoll(s.substr(0,1));
        long long b = stoll(s.substr(1,1));
    	if(b >= a) cout<<a;
        else cout<<a-1;
    
    }
    else if(nn <= 3){cout<<i2;}
    else if (nn<=4){
    	long long a = stoll(s.substr(0,2));
        long long b = stoll(s.substr(2,2));
    	if(b >= a) cout<<a-10+1+i2;
        else cout<<a-10+i2;
    }
    else if(nn <=5){
    	cout<<i2+i4;
    }
    else if(nn <=6){
    	long long a = stoll(s.substr(0,3));
        long long b = stoll(s.substr(3,3));
    	if(b >= a) cout<<a-100+1+i2+i4;
        else cout<<a-100+i2+i4;
    }
    else if(nn <= 7){
     cout<<i2+i4+i6;
    }
    else if(nn <= 8){
    	long long a = stoll(s.substr(0,4));
        long long b = stoll(s.substr(4,4));
    	if(b >= a) cout<<a-1000+1+i2+i4+i6;
        else cout<<a-1000+i2+i4+i6;
    }
    else if(nn <= 9){
    	cout<<i2+i4+i6+i8;
    }
    else if(nn <= 10){
    	long long a = stoll(s.substr(0,5));
        long long b = stoll(s.substr(5,5));
    	if(b >= a) cout<<a-10000+1+i2+i4+i6+i8;
        else cout<<a-10000+i2+i4+i6+i8;
    
    }
    else if(nn <= 11){
      cout<<i2+i4+i6+i8+i10;
    
    }
    else if(nn <= 12){
    	long long a = stoll(s.substr(0,6));
        long long b = stoll(s.substr(6,6));
    	if(b >= a) cout<<a-100000+1+i2+i4+i6+i8+i10;
        else cout<<a-100000+i2+i4+i6+i8+i10;
    
    
    }
    return 0;
}