import java.math.BigInteger;

public class Euler63 {
    private static boolean runCheckpoints = true;

    public static void main(String[] args) {
        for (int i = 0; i < args.length; i++) {
            if ("--skip-checkpoints".equals(args[i])) {
                runCheckpoints = false;
            } else {
                System.err.println("Unknown argument: " + args[i]);
                System.exit(1);
            }
        }

        if (runCheckpoints && !runCheckpoints()) {
            System.exit(2);
        }

        System.out.println(solve());
    }

    private static int digitCount(BigInteger x) {
        return x.toString().length();
    }

    private static int solve() {
        int total = 0;

        for (int base = 1; base <= 9; base++) {
            BigInteger value = BigInteger.ONE;
            for (int power = 1; ; power++) {
                value = value.multiply(BigInteger.valueOf(base));
                int digits = digitCount(value);
                if (digits == power) {
                    total++;
                }
                if (digits < power) {
                    break;
                }
            }
        }

        return total;
    }

    private static boolean runCheckpoints() {
        BigInteger value = BigInteger.ONE;
        for (int i = 0; i < 21; i++) {
            value = value.multiply(BigInteger.valueOf(9));
        }
        if (digitCount(value) != 21) {
            System.err.println("Checkpoint failed for 9^21");
            return false;
        }
        return true;
    }
}
