n = int(input())

cnt = 0
i = 1
while i < n:
    is_broken = False
    string = list(str(i))
    for j, s in enumerate(string):
        if s not in ['3', '5', '7']:
            i = i + 10**(len(string) - j - 1)
            is_broken = True
            break
    if is_broken:
        continue

    c1 = string.count('3') >= 1
    c2 = string.count('5') >= 1
    c3 = string.count('7') >= 1
    if c1 and c2 and c3:
        cnt += 1

    i += 1

print(cnt)