def get_count(num): count = 0 # 自守数的个数 for n in range(num+1): np = pow(n,2) length = len(str(n)) if int(str(np)[-length:]) == n: # 自守数的条件 count += 1 return count while True: try: n = int(input()) print(get_count(n)) except: break