n=input()
# 计算十进制各个位置的加和
def f(n1):
str_n=str(n1)
sum_n=0
for i in range(len(str_n)):
sum_n+=int(str_n[i])
return sum_n
# print(f(123))
# 计算相应二进制各个位置的加和
def g(n2):
bin_n=bin(n2)
str_n1=str(bin_n)
str_n=str_n1[2:]
sum_n=0
for i in range(len(str_n)):
sum_n+=int(str_n[i])
return sum_n
# print(g(123))
x=int(n)
n = 0
for j in range(1,x+1):
# 寻找符合条件的幸运数
if f(int(j))==g(int(j)):
n+=1
print(n)