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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;
const ll M = 1e9 + 1;

int main()
{
	scanf("%lld",&N);

	ll ans = 0;
	FOR(i,1,10){
		ll c = i;
		while(c <= N / M){
			c = c * 10 + i;
			ans++;
		}
	}
	printf("%lld\n",ans);

	return 0;
}