CodeEff/ECCO huggingface dataset:
# Original solution
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from collections import deque
    d = deque()
    lc = [3,5,7]
    cnt = 0
    #nya = 0
    d.append(0)
    LIST = []
    n = int(eval(input()))
    flag = False
    while True:

        a = d.popleft()
        #print(a)
        if a > n:
            #print(a,nya)
            print(cnt)
            exit()        #print(n,a)
        if len(str(a)) == 3 and (not flag):

            flag = True
        if flag and (str(a).count('3') >= 1 and str(a).count('5') >= 1 and str(a).count('7') >= 1):
            cnt += 1
        for i in range(3):
            nya = a * 10 + lc[i]
            d.append(nya)
if __name__ == '__main__':
  main()


# Optimized solution
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(eval(input()))
    nl = len(str(n))

    from collections import deque
    que = deque()

    selec = [3,5,7]
    que.append(0)
    ans = 0
    swi = False
    while que:
        a = que.popleft()
        sa = str(a)
        #print(a,sa,n)
        for i in range(3):
            que.append(a*10 + selec[i])
        if a > n:
            break
        elif (not swi) and sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:
            swi = True
            ans += 1
        elif sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
  main()
# Original solution
def dfs(s,num):
    if int(s)>num:
        return 0
    if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
        ret=1
    else:
        ret=0
    for i in "753":
        ret+=dfs(s+i,num)
    return ret
n=int(eval(input()))
print((dfs('0',n)))

# Optimized solution
n=int(eval(input()))

def dfs(now):
    if int(now)>n:
        return 0
    for i in "753":
        if i not in now:
            ret=0
            break
    else:
        ret=1
    for i in "753":
        ret+=dfs(now+i)
    return ret
print((dfs("0")))
# Original solution
import itertools

n  = int(eval(input()))

if n < 357:
  print((0))
  exit()

max_m = len(str(n))

ans = 0

for m in range(3,max_m+1):
  for i in range(1, m):
    for j in range(1, m-i):
      k = m-i-j
      ls = ['7']*i+['5']*j+['3']*k
      for l in set(itertools.permutations(ls)):
        s = ''.join(l)
        s = int(s)
        if s <= n:
          ans += 1
          #print(s)
print(ans)

# Optimized solution
n = int(eval(input()))

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

print((dfs('0')))
# Original solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = str(n)
m = len(str(n))

lst = [3,5,7]
que = deque([3,5,7])
for _ in range(3**m):
    x = que.popleft()
    for j in [3,5,7]:
        que.append(int(str(x)+str(j)))
        lst.append(int(str(x)+str(j)))

ans = 0
for i in lst:
    if i > n:
        break
    cnt = [0]*3
    for j in str(i):
        cnt[(int(j)-1)//3] += 1
    for j in cnt:
        if j == 0:
            break
    else:
        ans += 1
print(ans)

# Optimized solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
num = ['7', '5', '3']
stack = [('', 0)]
ans = 0
check = defaultdict(lambda:True)
while stack:
    m, l = stack.pop()
    for x in num:
        if x not in m:
            break
    else:
        ans += 1
    for x in num:
        if 10 * l + int(x) <= n:
            if check[10*l + int(x)]:
                stack.append((m + x, 10 * l + int(x)))
                check[10*l + int(x)] = False
print(ans)
# Original solution
from collections import Counter
N = int(eval(input()))

def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = ''.join(ls)
    return int(strnum)
def dfs(num_ls):
    '''
    引数のnum_ls以降の753numの総数を返す
    '''
    if change_to_num(num_ls) > N:
        return 0
    
    tmp = 0
    # 引数のnum_lsは753か？
    c = Counter(num_ls)
    is753 = True
    for num in [7,5,3]:
        if c[num] == 0:
            is753 = False
    if is753:
        tmp += 1
    
    # 次の状態の753総数を足す
    for num in [7,5,3]:
        num_ls.append(num)
        tmp += dfs(num_ls)
        num_ls.pop()
    return tmp
print((dfs([0])))


    

# Optimized solution
from collections import Counter
n = int(eval(input()))
ans = 0
def dfs(A):
    if A and int(A) > n:
        return
    if len(A) >= 3:
        c = Counter(A)
        is753 = True
        for i in ['7','5','3']:
            if c[i] < 1:
                is753 = False
        if is753:
            global ans 
            ans += 1
    for nex in ['7','5','3']:
        A += nex
        dfs(A)
        A = A[:-1]
dfs('')
print(ans)
# Original solution
N=int(eval(input()))

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans=[]
for i in range(4**len(str(N))):
    num=Base_10_to_n(i,4).zfill(len(str(N))+1).replace('0','').replace('1','7').replace('2','5')
    # print(num)
    if set(list(num))==set(['3','5','7']) and int(num)<=N:
        ans.append(num)
print((len(set(ans))))




# Optimized solution
N=int(eval(input()))
N_num=len(str(N))
ans=0

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

for i in range(3,N_num+1):#i桁についての3進数演算
    for j in range(3**i):
        num=Base_10_to_n(j,3).zfill(i).replace('0','3').replace('1','5').replace('2','7')
        if set(list(num))==set(['3','5','7']) and int(num)<=N:
            ans+=1
print(ans)
# Original solution
n=int(eval(input()))

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(10):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)
      


# Optimized solution
n=int(eval(input()))

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(8):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)
# Original solution
import itertools
n = eval(input())
number = list("753")
N = []
flag = False
for i in range(3, 10):
  for v in itertools.product(number, repeat=i):
    if "7" in v and "5" in v and "3" in v:
      if int("".join(v)) <= int(n): N.append(int("".join(v)))
print((len(N)))

# Optimized solution
import itertools
n = int(eval(input()))
cnt = 0
for i in range(3,len(str(n))+1):
    for v in itertools.product(["3","5","7"], repeat=i):
        if len(set(v))!=3: continue
        x = int("".join(v))
        if n >= x: cnt += 1

print(cnt)
# Original solution
import sys
from itertools import product
from bisect import bisect_right as bi_r

shichigosan = set('357')

cand = []
for i in range(3, 10):
    for x in product('357', repeat=i):
        x = ''.join(x)
        if set(x) == shichigosan:
            cand.append(int(''.join(x)))

n = int(sys.stdin.readline().rstrip())

def main():
    return bi_r(cand, n)

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys
from itertools import product
from bisect import bisect_right as bi_r

cand = [int(''.join(p)) for i in range(3, 10) for p in product('357', repeat=i) if len(set(p)) == 3]

n = int(sys.stdin.readline().rstrip())

def main():
    print((bi_r(cand, n)))

if __name__ ==  '__main__':
    main()
# Original solution
N = int(eval(input()))

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

print((dfs('0'))) 

# Optimized solution
N = int(eval(input()))

def func(s, cnt):
    if int(s)>N:
        return cnt
    else:
        b=list(s)
        if '7' in b and '5' in b and '3' in b:
            cnt += 1
        for t in "753":
            cnt = func(s+t, cnt)
        return cnt
    
print((func("0", 0)))
# Original solution
import itertools
N = int(eval(input()))
p = 3
digits = [3, 5, 7]
A = []
flag = False
while True:
    for tup in itertools.product(digits, repeat=p):
        a = int("".join(list(map(str, tup))))
        if a > N:
            flag = True
            break
        A.append(a)
    if flag:
        break
    p += 1
count = 0
for a in A:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        count += 1
print(count)


# Optimized solution
import itertools
N = int(eval(input()))
digits = [3, 5, 7]


def get_A_product(digits, N):
    A = []
    flag = False
    p = 3
    while True:
        for tup in itertools.product(digits, repeat=p):
            a = int("".join(list(map(str, tup))))
            if a > N:
                flag = True
                break
            A.append(a)
        if flag:
            break
        p += 1
    return A


count = 0
A = get_A_product(digits, N)
for a in A:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        count += 1
print(count)
# Original solution
from itertools import product
n = int(eval(input()))
num = ["","3","5","7"]
A = set() 
for i in product(num,repeat=9):
	x = "".join(i)
	if x == "":
		continue
	elif len(set(x)) < 3:
		continue
	elif int(x) not in A and int(x) <= n:
		A.add(int(x))
print((len(A)))

# Optimized solution
from itertools import product
n = int(eval(input()))
cnt = 0
for i in range(3, len(str(n))+1):
	for p in product(["7","5","3"], repeat = i):
		if len(set(p)) == 3:
			p = int("".join(p))
			if p <= n:
				cnt += 1
print(cnt)
# Original solution
from itertools import product
n = int(eval(input()))
num = ['','3','5','7']
A = set() 
for i in product(num,repeat=9):
    x = "".join(i)
    if len(set(x)) == 3:
        if (int(x) not in A) and (int(x) <= n):
            A.add(int(x))
print((len(A)))

# Optimized solution
N = int(eval(input()))
num = ['3','5','7']
for i in range(len(str(N))-1):
    num2 = []
    for n in num:
        num2.append(n+'3')
        num2.append(n+'5')
        num2.append(n+'7')
        num2.append(n)
    num = num2
cnt = 0
num = set(num)
for n in num:
    if '3' in n and '5' in n and '7' in n:
        if int(n) <= N:
            cnt += 1
print(cnt)
# Original solution
N = int(eval(input()))
M = len(str(N))
count = 0

def dfs(A):
  global count
  
  if len(A) <= M and (3 in A and 5 in A and 7 in A):
    num = 0
    for i in range(len(A)):
      num += A[i]*(10**i)
    if num <= N:
      count += 1
  elif len(A) > M:
    return

  for i in [3, 5, 7]:
    A.append(i)
    dfs(A)
    A.pop()
  
dfs([])
print(count)
    

# Optimized solution
def func(cur, use):
  
  global counter
  if (cur > N): return 
  if (use == 0b111): counter += 1

  func(cur * 10 + 7, use | 0b001)
  func(cur * 10 + 5, use | 0b010)
  func(cur * 10 + 3, use | 0b100) 

N = int(eval(input()))
counter = 0
func(0, 0)
print(counter)
# Original solution
import sys
sys.setrecursionlimit(100000)
N = int(eval(input()))
svt = []

def dfs(num):
    if num>1000000000:
        return
    #elif num<100:
    #    return
    else:
        svt.append(int(str(num)+'3'))
        dfs(int(str(num)+'3'))
        svt.append(int(str(num)+'5'))
        dfs(int(str(num)+'5'))
        svt.append(int(str(num)+'7'))
        dfs(int(str(num)+'7'))

def check753(num):
    exist3 = False
    exist5 = False
    exist7 = False
    s = str(num)
    for c in s:
        if c=='3':
            exist3 = True
        elif c=='5':
            exist5 = True
        elif c=='7':
            exist7 = True
    if exist3 and exist5 and exist7:
        return True
    else:
        return False


dfs(0)
svt = sorted(svt)
svt = svt[12:]
#print(svt)
count = 0
for i in range(len(svt)):
    if svt[i]>N:
        break
    if check753(svt[i]):
        count += 1
print(count)



# Optimized solution
N = int(eval(input()))

cnt = 0
def dfs(n):
    global cnt
    if n>N:
        return 0
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        cnt += 1
    dfs(int(s+'3'))
    dfs(int(s+'5'))
    dfs(int(s+'7'))

dfs(3)
dfs(5)
dfs(7)
print(cnt)
# Original solution
def main():
    N = int(eval(input()))

    def recur(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 += recur(s + c)
        return ret
    print((recur('0')))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product
    ans_set = set()
    for k in range(3, N_len+1):
        ans_set = ans_set.union({s for s in product("753", repeat=k)
                                 if int("".join(s)) <= N and
                                 len(set(s) & set("753")) == 3})
    print(len(ans_set))


if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(s)
    else:
        ret = 0
    ret += dfs(s + "7")
    ret += dfs(s + "5")
    ret += dfs(s + "3")
    return ret


print((dfs("0")))



# Optimized solution
N = int(eval(input()))


def dfs(x):
    if x > N:
        return 0
    s = str(x)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(x)
    else:
        ret = 0
    ret += dfs(10 * x + 7)
    ret += dfs(10 * x + 5)
    ret += dfs(10 * x + 3)
    return ret


print((dfs(0)))
# Original solution
# -*- coding: utf-8 -*-

N = int(eval(input()))

ans = 0
cursor = "357"


def increment(cursor):
    l = len(cursor)
    ret = [''] * (l + 1)
    if cursor[-1] == '7':
        ret[-1] = '3'
        ret[-2] = '3'
    elif cursor[-1] == '5':
        ret[-1] = '7'
    elif cursor[-1] == '3':
        ret[-1] = '5'

    for i in range(l-1):
        if ret[-(2 + i)] == '3':
            if cursor[-(2 + i)] == '7':
                ret[-(2 + i)] = '3'
                ret[-(3 + i)] = '3'
            elif cursor[-(2 + i)] == '5':
                ret[-(2 + i)] = '7'
            elif cursor[-(2 + i)] == '3':
                ret[-(2 + i)] = '5'
        else:
            ret[-(2 + i)] = cursor[-(2 + i)]

    return ''.join(ret)


while N >= int(cursor):
    if '7' in cursor and '5' in cursor and '3' in cursor:
        ans += 1
    cursor = increment(cursor)

print(ans)


# Optimized solution
from itertools import product

N = int(eval(input()))
ans, L = 0, len(str(N))
for i in range(L + 1):
    for p in product(("7", "5", "3"), repeat=i):
        if "7" in p and "5" in p and "3" in p:
            if (i == L and int(''.join(p)) <= N) or i < L:
                ans += 1
print(ans)
# Original solution
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(N):
    q = deque(["3", "5", "7"])

    cnt = 0
    while q:
        s = q.popleft()

        if int(s) > N:
            continue

        if len(set(s)) == 3:
            cnt += 1

        for c in ["3", "5", "7"]:
            q.append(s + c)

    return cnt


def main():
    N = int(eval(input()))
    ans = bfs(N)
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(N):
    q = deque(["7", "5", "3"])
    res = []

    while q:
        s = q.popleft()

        for c in ["7", "5", "3"]:
            new = s + c

            if int(new) > N:
                continue

            if "7" in new and "5" in new and "3" in new:
                res.append(new)

            q.append(new)

    return len(res)


def main():
    N = int(eval(input()))

    ans = bfs(N)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N = int(eval(input()))
s = "357"
cnt = 0
for i in range(1,10):
    for j in range(3**i):
        n = j
        t = ""
        for k in range(i):
            t+=s[n%3]
            n//=3
        if len(set(t))!=3:continue
        if int(t)<=N:cnt+=1
print(cnt)

# Optimized solution
from collections import deque
N = int(eval(input()))
ans = 0
A = "357"
Q = deque(["3","5","7"])
while Q:
    q = Q.pop()
    x = int(q)
    if x>N:continue
    if len(set(q))==3:ans+=1
    for a in A:
        Q.append(q+a)
print(ans)
# Original solution
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(eval(input()))

    digits = [0, 3, 5, 7]
    ans = 0
    for i in range(4**9):
        cur = 0
        for j in range(10):
            cur += digits[i % 4] * 10 ** j
            i //= 4

        num = cur
        cnt = [0] * 10
        while num:
            cnt[num % 10] += 1
            num //= 10

        if cur <= n and not cnt[0] and cnt[3] and cnt[5] and cnt[7]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
N = int(eval(input()))


def solve(x, t, f, s):
    if x > N:
        return 0

    res = 0
    if t and f and s:
        res += 1

    res += solve(x*10+3, t+1, f, s)
    res += solve(x*10+5, t, f+1, s)
    res += solve(x*10+7, t, f, s+1)

    return res


def main():
    print((solve(0, 0, 0, 0)))


if __name__ == '__main__':
    main()
# Original solution
n=int(eval(input()))

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

print((dfs("0")))

# Optimized solution
n=int(eval(input()))

def dfs(s):
    if int(s)>n:
       return 0
    b=(all(map(s.count,"357")))
    for c in "357":
        b+=dfs(s+c)
    return b
print((dfs("0")))
# Original solution
import bisect
N = int(eval(input()))
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(int(str(j)+str(k)))
S = list(sorted(S))
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
print((bisect.bisect_right(T,N)))

# Optimized solution
import bisect
N = int(eval(input()))
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(10*j+k)
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
T.sort()
print((bisect.bisect_right(T,N)))
# Original solution
n=int(eval(input()))
s=[]
def dfs(string,cur):
  if cur==len(str(n)):
    if string.count('3')>0 and string.count('5')>0 and string.count('7'):
      s.append(string)
    return
  dfs(string+"",cur+1)
  dfs(string+"7",cur+1)
  dfs(string+"5",cur+1)
  dfs(string+"3",cur+1)
dfs("",0)

cnt=0
for i in set(s):
  if int(i)<=n:
    cnt+=1
print(cnt)

# Optimized solution
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")))
# Original solution
#!/usr/bin/env python3
n = int(eval(input()))

def dfs(k):  # k : str
    if int(k) > n: return 0
    c = 1 if all(k.count(t) for t in "753") else 0  # k judge
    for t in "753":
        c += dfs(k + t)
    return c
print((dfs("0")))

# Optimized solution
#!/usr/bin/env python3
from itertools import*
n = int(eval(input()))
c = 0
k = "357"

for i in range(3, -~len(str(n))):
    for j in product(k, repeat = i):
        if all(j.count(h) for h in k):
            if int("".join(j)) <= n:
                c += 1
print(c)
# Original solution
n = (int)(eval(input()))

def f(s):
    ans = 0
    if (int)(s) > n:
        return 0
    for c in '753':
        num = (str)(s+c)
        if (int)(num) <= n:
            if num.count('3')and num.count('5') and num.count('7'):
                ans += 1
            ans += f(num)
    return ans
print((f('0')))


# Optimized solution
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(eval(input()))


ans = 0


def check(s: str)->bool:
    return '3' in s and '5' in s and '7' in s


def dfs(s: str)->int:
    ret = 0
    if int(s) > N:
        return 0
    else:
        if check(s):
            ret += 1
        r3 = dfs(s+"3")
        r5 = dfs(s+"5")
        r7 = dfs(s+"7")

        ret += r3+r5+r7
    return ret


print((dfs("0")))
# Original solution
N = int(eval(input()))

def dfs(s):
    if int(s) > N:
        return 0
    ans = 1 if all (s.count(c) > 0 for c in "753") else 0
    
    for c in "753":
        ans += dfs(s+c)
    return ans
print((dfs('0')))

# Optimized solution
# ABC114

N = int(eval(input()))
def dfs(num):
    if num > N:
        return 0
    flag = True
    for s in "357":
        if str(num).count(s) >= 1:
            pass
        else:
            flag = False
    ret = 1 if flag else 0

    for c in [3, 5, 7]:
        ret += dfs(num * 10 + c)
    return ret
ans = dfs(0)
print(ans)
# Original solution
# ABC114

N = int(eval(input()))
def dfs(num):
    if num > N:
        return 0
    flag = True
    for s in "357":
        if str(num).count(s) >= 1:
            pass
        else:
            flag = False
    ret = 1 if flag else 0

    for c in [3, 5, 7]:
        ret += dfs(num * 10 + c)
    return ret
ans = dfs(0)
print(ans)

# Optimized solution
# ABC114

N = int(eval(input()))
def dfs(num, use):
    if num > N:
        return 0
    cnt = 1 if use == 0b111 else 0
    cnt += dfs(num*10 + 3, use | 0b001)
    cnt += dfs(num*10 + 5, use | 0b010)
    cnt += dfs(num*10 + 7, use | 0b100)
    return cnt
ans = dfs(0, 0)
print(ans)