import itertools
n=int(input())
h = list(itertools.product(['7','5','3'],repeat=len(str(n))))
s=[0, 0, 0, 6, 36, 150, 540, 1806, 5796, 18150]
cnt=sum(s[:len(str(n))])
if n < 100:
    print(0)
else:
    for i in h:
        if any([j not in i for j in ['7','5','3']]):
            continue
        else:
            t=int(''.join(i))
            if n >= t:
                cnt+=1

print(cnt)