N=int(input())
X,Y=("7","5","3"),("0","1","2","4","6","8","9")
a=0
for i in range(1,N):
    i=str(i)
    b=0
    for j in X:
        if not j in i:b=1
    for k in Y:
        if k in i:b=1
    if b==0:
        a+=1
print(a)