N = int(input())
ary = '357'
def f(s):
    if int(s) > N:
        return 0
    cnt = 1 if all(s.count(c) > 0 for c in ary) else 0
    for c in ary:
        cnt += f(s + c)
    return cnt
    
print(f("0"))