while True:
    try:
        num = int(input())
        count = 0 #记录自守数的个数
        for i in range(num+1): #从0计算到num
            a = pow(i, 2) #计算i的平方
            b = str(i) #将i变为字符串
            c = str(a) #将i的平方变为字符串
            if(c[-1*len(b):] == b): #如果在c的最后len(b)个字符与b一样,认为i是自守数
                count += 1 #自守数加一
        print(count)
    except:
        break