import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int n = scan.nextInt();
            int count = 0;
            for (int i = 0; i <= n; i++) {
                int x = i * i;
                if (x % 10 == i || x == i || x % 100 == i || x % 1000 == i || x % 10000 == i) {
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}