import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
    	
    	if (A < 10) {
	        System.out.println(A);
    		return ;
    	}
    	if (A < 100) {
	        System.out.println(9);
    		return ;
    	}
    	if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	}
    	if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	}
    	if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	}
	    System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
    	
    	if (A < 10) {
	        System.out.println(A);
    		return ;
    	}
    	if (A < 100) {
	        System.out.println(9);
    		return ;
    	}
    	if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	}
    	if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	}
    	if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	}
	    System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
    	
    	if (A < 10) {
	        System.out.println(A);
    		return ;
    	}
    	if (A < 100) {
	        System.out.println(9);
    		return ;
    	}
    	if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	}
    	if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	}
    	if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	}
	    System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9);
    } main {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
    	
    	if (A < 10) {
	        System.out.println(A);
    		return ;
    	}
    	if (A < 100) {
	        System.out.println(9);
    		return ;
    	}
    	if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	}
    	if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	}
    	if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	}
	    System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int A = sc.nextInt(); A sc.nextInt() sc.nextInt sc if (A < 10) {
	        System.out.println(A);
    		return ;
    	} A < 10 A 10 {
	        System.out.println(A);
    		return ;
    	} System.out.println(A) System.out.println System.out System System.out A return ; if (A < 100) {
	        System.out.println(9);
    		return ;
    	} A < 100 A 100 {
	        System.out.println(9);
    		return ;
    	} System.out.println(9) System.out.println System.out System System.out 9 return ; if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	} A < 1000 A 1000 {
	        System.out.println(A-10*10+9+1);
    		return ;
    	} System.out.println(A-10*10+9+1) System.out.println System.out System System.out A-10*10+9+1 A-10*10+9+1 A-10*10 A 10*10 10 10 9 1 return ; if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	} A < 10000 A 10000 {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	} System.out.println(10*10*10-10*10+9) System.out.println System.out System System.out 10*10*10-10*10+9 10*10*10-10*10 10*10*10 10*10*10 10 10 10 10*10 10 10 9 return ; if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	} A < 100000 A 100000 {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	} System.out.println(A-10*10*10*10+10*10*10-10*10+9+1) System.out.println System.out System System.out A-10*10*10*10+10*10*10-10*10+9+1 A-10*10*10*10+10*10*10-10*10+9+1 A-10*10*10*10+10*10*10-10*10 A-10*10*10*10+10*10*10 A-10*10*10*10 A 10*10*10*10 10 10*10*10*10 10 10 10 10 10*10*10 10*10*10 10 10 10 10*10 10 10 9 1 return ; System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9) System.out.println System.out System System.out 10*10*10*10*10-10*10*10*10+10*10*10-10*10+9 10*10*10*10*10-10*10*10*10+10*10*10-10*10 10*10*10*10*10-10*10*10*10+10*10*10 10*10*10*10*10-10*10*10*10 10*10*10*10*10 10 10 10*10*10*10*10 10 10 10 10 10 10*10*10*10 10 10*10*10*10 10 10 10 10 10*10*10 10*10*10 10 10 10 10*10 10 10 9 String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
    	
    	if (A < 10) {
	        System.out.println(A);
    		return ;
    	}
    	if (A < 100) {
	        System.out.println(9);
    		return ;
    	}
    	if (A < 1000) {
	        System.out.println(A-10*10+9+1);
    		return ;
    	}
    	if (A < 10000) {
	        System.out.println(10*10*10-10*10+9);
    		return ;
    	}
    	if (A < 100000) {
	        System.out.println(A-10*10*10*10+10*10*10-10*10+9+1);
    		return ;
    	}
	    System.out.println(10*10*10*10*10-10*10*10*10+10*10*10-10*10+9);
    }
}