while True:
    try:
        n = int(input())
        ans = 0
        
        for i in range(0,n+1):
            s = i*i
            list1 = list(str(s))
            list2 = list(str(i))
            v = len(list1)
            p = len(list2)
            if i==s or list2 == list1[v-p:]:
                ans += 1
        print(ans)
    except:
        break