while True:
    try:
        n = int(input())
        if n == 0:
            print(1)
        elif n == 1:
            print(2)
        else:#n >= 2
            res = 2
            i = 5#除了0,1,只有个位数是 5 或 6 才有可能是自守数
            while i <= n:
                if str(i**2).endswith(str(i)):
                    res += 1
                if i+1<= n and str((i+1)**2).endswith(str(i+1)):
                    res += 1
                i += 10
            print(res)
    except:
        break