n = int(input())

def next(x):
    if(x==""):
        return "3"
    if(x[-1]=="3"):
        return x[0:-1]+"5"
    if(x[-1]=="5"):
        return x[0:-1]+"7"
    if(x[-1]=="7"):
        return next(x[0:-1])+"3"

cnt=0
a = "3"
while(int(a) < n):
    if all([c in a for c in "753"]):
        cnt += 1
    a = next(a)

print(cnt)
