N = int(input().rstrip())
c = 0
for i in range(0,N):
    S = str(i)
    if "7" in S and "5" in S and "3" in S:
        if "0" not in S and "1" not in S and "2" not in S and "4" not in S and "6" not in S and "8" not in S and "9" not in S:
            c += 1
print(c)