f(n,t){return n<10?t=pow(10,t=log10(n)),f(n%t/10)*10-n/t*~t:n;}long n,x=1+1e9;main(m){scanf("%ld",&n);m=log10(n/=x);printf("%d",n=n/pow(10,-~m/2)-~(m%2*9)*pow(10,m/2)-2+(f(n)<=n));}