def make_candidate(N, seed, l):
    seed3 = seed+"3"
    seed5 = seed+"5"
    seed7 = seed+"7"

    if int(seed3) < N:
        l.append(seed3)
        l = make_candidate(N, seed3, l)
    
    if int(seed5) < N:
        l.append(seed5)
        l = make_candidate(N, seed5, l)
    
    if int(seed7) < N:
        l.append(seed7)
        l = make_candidate(N, seed7, l)
    
    return l


N = int(input())

l = make_candidate(N, "3", [])
l = make_candidate(N, "5", l)
l = make_candidate(N, "7", l)

num = 0
for n in l:
    s = str(n)
    exist = s.count('3') * s.count('5') * s.count('7')

    if exist>0:
        num = num + 1

print(num)
