import java.util.*; public class No491{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long tmp = (long)Math.pow(10, 9) + 1; if(N < tmp) System.out.println(0); else{ long div = 1; long ans = 0; for(int digit = 1; digit < 10; digit++){ for(int i = 1; i < 10; i++){ if(N >= tmp*digitmul(digit, i)) ans++; else break; } } System.out.println(ans); } } private static long digitmul(long digit, long n){ long v = 0; for(int i = 0; i < digit; i++){ v += n*Math.pow(10, i); } return v; // return 11, 222, 5555, ... } }