n=int(input())

#base=["357","375","537","573","735","753"]
arr=["3","5","7"]
for i in range(9):
    t_arr=[]
    for i in arr:
        t_arr.append("3"+i)
        t_arr.append("5"+i)
        t_arr.append("7"+i)
    arr.extend(t_arr)
#print(len(arr))

count=0
for i in set(arr):
    if n>int(i) and "3" in i and "5" in i and "7" in i:
        count+=1
        #print(i)
print(count)
