n = int(input())

def doit(num):
    if num and int(num) > n:
        return 0
    count = all(d in num for d in '735')
    for d in '735':
        count += doit(num + d)
    return count

print(doit(''))
