from collections import deque

from collections import Counter

n=int(eval(input()))

if n<357:

    print((0))

    exit()

i=357

ans=0

while i<=n:

  c=Counter(str(i))

  if '3' in c and '5' in c and '7' in c:

    if c['3']+c['5']+c['7']==len(str(i)):

      ans+=1

  a=list(map(int,list(str(i))))

  a[-1]+=2

  j=-1

  while a[j]>7 and -j<len(a):

    a[j]=3

    a[j-1]+=2

    j-=1

  if a[0]>7:

    a[0]=33

  i=int(''.join(map(str,a)))



print(ans)

n=int(eval(input()))

def dfs(s):

  if int(s)>n:

    return 0

  ret=1 if all(s.count(c) for c in '753') else 0

  for c in '753':

    ret+=dfs(s+c)

  return ret

print((dfs('0')))
from collections import deque
from collections import Counter

n = int(eval(input()))
if n < 357:
    print((0))
    exit()
i = 357
ans = 0
while i <= n:
    c = Counter(str(i))
    if "3" in c and "5" in c and "7" in c:
        if c["3"] + c["5"] + c["7"] == len(str(i)):
            ans += 1
    a = list(map(int, list(str(i))))
    a[-1] += 2
    j = -1
    while a[j] > 7 and -j < len(a):
        a[j] = 3
        a[j - 1] += 2
        j -= 1
    if a[0] > 7:
        a[0] = 33
    i = int("".join(map(str, a)))
print(ans)

n = int(eval(input()))


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


print((dfs("0")))

-from collections import deque -from collections import Counter +n = int(eval(input())) -n = int(eval(input())) -if n < 357: -    print((0)) -    exit() -i = 357 -ans = 0 -while i <= n: -    c = Counter(str(i)) -    if "3" in c and "5" in c and "7" in c: -        if c["3"] + c["5"] + c["7"] == len(str(i)): -            ans += 1 -    a = list(map(int, list(str(i)))) -    a[-1] += 2 -    j = -1 -    while a[j] > 7 and -j < len(a): -        a[j] = 3 -        a[j - 1] += 2 -        j -= 1 -    if a[0] > 7: -        a[0] = 33 -    i = int("".join(map(str, a))) -print(ans) + +def dfs(s): +    if int(s) > n: +        return 0 +    ret = 1 if all(s.count(c) for c in "753") else 0 +    for c in "753": +        ret += dfs(s + c) +    return ret + + +print((dfs("0")))