N=input()

if len(N)<3:
    print(0)
else:
    arr=set([357, 375, 537, 573, 735, 753])
    for i in range(len(N)-3):
        new=set()
        for num in arr:
            for j in range(len(str(num))+1):
                n=str(num)[:j]+'3'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'5'+str(num)[j:]
                new.add(int(n))
                n=str(num)[:j]+'7'+str(num)[j:]
                new.add(int(n))
        arr |= new

arr=list(arr)
arr.sort()
cnt=0
for i in range(len(arr)):
    if arr[i]<=int(N):
        cnt+=1
    else:
        break
print(cnt)