import java.util.Scanner;

/**
 * JD9 幸运数
 * @author d3y1
 */
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            // solution1(in);
            // solution2(in);
            solution3(in);
        }
    }

    /**
     * 模拟法: 字符串转字符
     * @param in
     */
    private static void solution1(Scanner in){
        int n = in.nextInt();

        int result = 0;
        for(int i=1; i<=n; i++){
            if(f(i) == g(i)){
                result++;
            }
        }

        System.out.println(result);
    }

    /**
     * 模拟法: 数学运算
     * @param in
     */
    private static void solution2(Scanner in){
        int n = in.nextInt();

        int result = 0;
        for(int i=1; i<=n; i++){
            if(F(i) == G(i)){
                result++;
            }
        }

        System.out.println(result);
    }

    /**
     * 模拟法: 数学运算(位运算)
     * @param in
     */
    private static void solution3(Scanner in){
        int n = in.nextInt();

        int result = 0;
        for(int i=1; i<=n; i++){
            if(F(i) == G_(i)){
                result++;
            }
        }

        System.out.println(result);
    }

    /**
     * 十进制数字之和: 字符串转字符
     * @param x
     * @return
     */
    private static int f(int x){
        int sum = 0;
        char[] digits = String.valueOf(x).toCharArray();
        for(char digit: digits){
            sum += digit-'0';
        }

        return sum;
    }

    /**
     * 十进制数字之和: 数学运算
     * @param x
     * @return
     */
    private static int F(int x){
        int sum = 0;
        while(x > 0){
            sum += x%10;
            x /= 10;
        }

        return sum;
    }

    /**
     * 二进制数字之和: 字符串转字符
     * @param x
     * @return
     */
    private static int g(int x){
        int sum = 0;
        char[] digits = Integer.toBinaryString(x).toCharArray();
        for(char digit: digits){
            sum += digit-'0';
        }

        return sum;
    }

    /**
     * 二进制数字之和: 数学运算
     * @param x
     * @return
     */
    private static int G(int x){
        int sum = 0;
        while(x > 0){
            sum += x%2;
            x /= 2;
        }

        return sum;
    }

    /**
     * 二进制数字之和: 数学运算(位运算)
     * @param x
     * @return
     */
    private static int G_(int x){
        int sum = 0;
        while(x > 0){
            sum += x&1;
            x >>= 1;
        }

        return sum;
    }
}