from itertools import product
from bisect import bisect_left,bisect_right
#pre processing
st = '753'
ls = []
for i in range(3,10):
	s = list(product(st,repeat = i))
	for i in s:
		zz = ''.join(list(i))
		ls.append(zz)

arr = []
for i in ls:
	if '7' in i and '5' in i and '3' in i:
		arr.append(int(i))
arr.sort()
n = input()
print bisect_right(arr,n)
