import sys
check_str = "0156" #位数为0,1,5,6才可能是自守数
def calc_automorphic_numbers(n):
    count = 0
    for i in range(n+1):
        i_s = str(i%10)
        if i_s not in check_str:
            continue

        #先平方然后转成字符串,再判断是否以i结尾
        if str(i**2).endswith(str(i)):
            count += 1
    return count

while True:
    try:
        n = int(input())
        print(calc_automorphic_numbers(n))
    except:
#         print(sys.exc_info())
        break