n = input()
def ok(x):
    v = []
    while x > 0:
        v.append(x % 10)
        x /= 10
    return len(set(v)) == 3

def f(x):
    if x > n:
        return 0
    res = sum(f(10*x+i) for i in [7,5,3])
    if ok(x):
        res += 1
    return res
print(f(0))