N = input()
def rec(list1,list2,initial,time):
    for e in list1:
        for b in [0,1,2,3]:
            if b == 0:
                e_copy = e
                list2.append(e_copy)
            elif b == 1:
                e_copy = e + "3"
                list2.append(e_copy)
            elif b == 2:
                e_copy = e + "5"
                list2.append(e_copy)
            elif b == 3:
                e_copy = e + "7"
                list2.append(e_copy)
    list1.clear()
    # initial + 1 がn回目のループ
    if initial + 1 >= time :
        return list2
    else:
        return rec(list2,list1,initial + 1, time)
l1 = ["3","5","7"]
l2 = []
result = rec(l1,l2,0,len(N)-2)
result = [int(e) for e in result if e.count("3")*e.count("5")*e.count("7") >= 1]
result = list(set(result))
result.sort()
count = 0
for e in result:
    if int(N) < e:
        break
    count += 1
print(count)