N = int(input())
count = 0

for i in range(357, N+1):

    i_str = str(i)
 
    thr = i_str.count("3")
    fiv = i_str.count("5")
    sev = i_str.count("7")


    if len(i_str) == thr + fiv + sev:
        if thr > 0:
             if fiv > 0:
                if sev > 0: 
                    count += 1

print(count)
