N = int(raw_input())

l = ['0']
count = 0

while l:
    s = l.pop()
    if N < int(s):
        continue
    if s[0] == '0':
        s = s[1:]
    count_3 = 0
    count_5 = 0
    count_7 = 0
    for i in s:
        if i == '3':
            count_3 += 1
        elif i == '5':
            count_5 += 1
        elif i == '7':
            count_7 += 1
    if len(s) == (count_3 + count_5 + count_7) and count_3 and count_5 and count_7:
        count += 1
    for j in '357':
        l.append(s+j)

print count
