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

signed main()
{
	int n;
	cin>>n;
	for(int i=1;i<=1000000;++i)
	{
		int k=log10(i);
		int tmp=pow(10,k+1);
		//cout<<i*tmp+i<<'\n';
		if(i*tmp+i>n)
		{
			cout<<i-1<<'\n';
			break;
		}
	} 
   return 0;
}

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

int main(void){
  long long n;

  cin >> n;
  long long m = 1;
  long long k = 10;
  long long ans = 0;

  for(int i=1;i<1000000;i++){
    if(k <= i) k*=10;
    if(i*k+i <= n){
      ans++;
    } 
    if(i*k+i > n) break;
  }

  cout << ans << endl;
}