N = int(input())

n_753 = 0

for i in range(1, N+1):
    digit = str(i)
    for j in '0124689':
        if j in digit:
            break
    else:
        if '7' in digit and '5' in digit and '3' in digit:
            n_753 += 1

print(n_753)