
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	} main {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = Integer.parseInt(sc.nextLine()); num Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc sc.close() sc.close sc int ans = 0; ans 0 if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 10 num 10 {
			ans = num;
		} ans = num ans num if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 100 num 100 {
			ans = 9;
		} ans = 9 ans 9 if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 1000 num 1000 {
			ans = num - 99 + 9;
		} ans = num - 99 + 9 ans num - 99 + 9 num - 99 num 99 9 if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 10000 num 10000 {
			ans = 999 - 99 + 9;
		} ans = 999 - 99 + 9 ans 999 - 99 + 9 999 - 99 999 99 9 if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 100000 num 100000 {
			ans = num - 9999 + 999 - 99 + 9;
		} ans = num - 9999 + 999 - 99 + 9 ans num - 9999 + 999 - 99 + 9 num - 9999 + 999 - 99 num - 9999 + 999 num - 9999 num 9999 999 99 9 if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} num < 1000000 num 1000000 {
			ans = 99999 - 9999 + 999 - 99 + 9;
		} ans = 99999 - 9999 + 999 - 99 + 9 ans 99999 - 9999 + 999 - 99 + 9 99999 - 9999 + 999 - 99 99999 - 9999 + 999 99999 - 9999 99999 9999 999 99 9 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = Integer.parseInt(sc.nextLine());
		sc.close();
		int ans = 0;

		if (num < 10) {
			ans = num;
		} else if (num < 100) {
			ans = 9;
		} else if (num < 1000) {
			ans = num - 99 + 9;
		} else if (num < 10000) {
			ans = 999 - 99 + 9;
		} else if (num < 100000) {
			ans = num - 9999 + 999 - 99 + 9;
		} else if (num < 1000000) {
			ans = 99999 - 9999 + 999 - 99 + 9;
		}

		System.out.println(ans);

	}
}
