import queue
q = queue.Queue()
n = int(input())
cnt = 0
q.put(3)
q.put(5)
q.put(7)
while not q.empty():
    tmp = q.get()
    if tmp < n:
        if ('3' in str(tmp)) and ('7' in str(tmp)) and ('5' in str(tmp)):
            cnt += 1
        q.put(tmp*10 + 3)
        q.put(tmp*10 + 5)
        q.put(tmp*10 + 7)
    else:
        continue
print(cnt)