n=int(input())

def f(s):
    if int(s)>n:
        return 0
    elif all(s.count(c)>0 for c in '753'):
        t=1
    else:
        t=0
    for a in '753':
        t+=f(s+a)
    return t

print(f('0'))