N = int(input().strip())

def f(s):
    if int(s) > N:
        return 0
    
    ret = 1 if all([c in s for c in '753']) else 0
    for c in '753':
        ret += f(s + c)
    
    return ret

print(f('0'))