# -*- coding: utf-8 -*-
import itertools

n = int(input())
nlen = len(str(n))
A = ['3','5','7']
lis = [0,0,6,36,150,540,1806,5796,18150]
ans = 0
for i in itertools.product(A, repeat=nlen):
    string = "".join(i)
    if('3' in string and '5' in string and '7' in string) :
        if(int(string) < n):
            ans += 1
for i in range(nlen-1):
    ans += lis[i]
print(ans)

