N = int(input())
ans = 0


def f(s):

    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) for c in '753') else 0
    for c in '753':
        ret += f(s + c)
    return ret


print(f('0'))
