import itertools

d = [7,5,3,7,5,3,7,5,3]

X = int(input())

cnt = 0
e = 0

for i in range(3, len(str(X))+1):
    c = list(itertools.permutations(d, i))
    for j in set(c):
        if str(j).count("3") >= 1 and str(j).count("5") >= 1 and str(j).count("7") >= 1:
            e = int(''.join(map(str, j)))
            if X - e >= 0:
                cnt += 1
print(cnt)