import itertools
n = int(input())
ori = [3, 5, 7]
num = []
num.append(0)
ans = []
i = 1
while i < 10:
    num.append(list(itertools.product(ori, repeat=i)))
    for k in range(len(num[i])):
        if (3 in num[i][k]) and (5 in num[i][k]) and (7 in num[i][k]):
            ans.append(int(''.join([str(x) for x in num[i][k]])))
    i += 1
count = 0
for f in ans:
    if n > f:
        count += 1
print(count)