import bisect

n = int(input())
k = len(str(n))

k753_num = []
def get_k753_num(k, s):
  if k == 0:
    if "7" in s and "5" in s and "3" in s:
      k753_num.append(int(s))
      return True
    else:
      return False
  pata = get_k753_num(k-1, "7" + s)
  patb = get_k753_num(k-1, "5" + s)
  patc = get_k753_num(k-1, "3" + s)
  
def count_k753_num(k):
  if k<3:
    return 0
  else:
    return 3**k - (2**k * 3) + 3

# count up k-1 753 num
count = 0
for i in range(k):
  count += count_k753_num(i)

# add k 753 num
get_k753_num(k, "")
k753_num.sort()
count += bisect.bisect_left(k753_num, n)

print(count)