import numpy as np
N = int(input())
def chack(s):
    def f(s):
        return s == '5' or s == '3' or s == '7'
    if ('5' in s) & ('3' in s) & ('7' in s) :
        return all([ f(i) for i in s])
    return False
print(np.array([chack(str(i)) for i in range(0,N+1)]).sum())