CodeEff/ECCO huggingface dataset:
# Original solution
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(eval(input()))
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print((len(list333)))


# Optimized solution
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1int=lint*10+3
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2int=lint*10+5
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3int=lint*10+7
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 

def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(eval(input()))
for b in list753:
    cnct(b,k)
for c in [x for x in list357]:
    if not D(c):
        list357.remove(c)
print((len(list357)))
# Original solution
lista=[3,5,7]
count=0
lim=int(eval(input()))
while True:
    t=lista.pop(0)
    if t>lim:
        break
    c=list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count+=1
    lista.append(10*t+3)
    lista.append(10*t+5)
    lista.append(10*t+7)
print(count)

# Optimized solution
from collections import deque
lista=deque([3,5,7])
count=0
lim=int(eval(input()))
while True:
    t=lista.popleft()
    if t>lim:
        break
    c=list(str(t))
    if c.count("3") and c.count("5") and c.count("7"):
        count+=1
    lista.append(10*t+3)
    lista.append(10*t+5)
    lista.append(10*t+7)
print(count)
# Original solution
from collections import deque
N = int(eval(input()))
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "357":
        cs = c + s
        # print(cs)
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                cnt += 1
print(cnt)

# Optimized solution
"""
dfsでとき直し114
7,5,3がそれぞれ1回以上現れる

3-3-3
   -5
   -7
 -5-3
   -5
   -7
 -7-3
   -5
   -7
とかそういうヤツ

3 33 35 37 5 
"""

import sys
sys.setrecursionlimit(100000)

cnt = 0
num = "0"
X = int(eval(input()))
def dfs(num,is3,is5,is7):
    # print(num,is3 and is5 and is7)
    global cnt
    if is3 and is5 and is7:
        cnt += 1 
    N = "357"
    for n in N:
        if int(num+n) > X: continue #終了条件
        if n == "3":
            dfs(num+n,True,is5,is7)
        elif n == "5":
            dfs(num+n,is3,True,is7)
        elif n == "7":
            dfs(num+n,is3,is5,True)


dfs("0",0,0,0)
print(cnt)
# Original solution
from collections import deque
X = int(eval(input()))
# その時の数字と、3,5,7が今までに含まれていたか
q = deque([""])
q_is3 = deque([0])
q_is5 = deque([0])
q_is7 = deque([0])
N = "357"
ans = 0
while q:
    num = q.popleft()
    is3 = q_is3.popleft()
    is5 = q_is5.popleft()
    is7 = q_is7.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            next_is3 = is3 or n == "3"
            next_is5 = is5 or n == "5"
            next_is7 = is7 or n == "7"
            q.append(next_v)
            q_is3.append(next_is3)
            q_is5.append(next_is5)
            q_is7.append(next_is7)
            if next_is3 and next_is5 and next_is7:
                ans += 1
print(ans)


# Optimized solution
"""
753の数
"""

import sys
sys.setrecursionlimit(100000)
N = int(eval(input()))
# seen = [False] * N
"""
1. Gを予め作って探索するパターン
2. Gを作りながら探索するパターン
"""
cnt = 0
def dfs(v):
    global cnt
    # vを訪問済みにする
    # seen[v] = True
    num = "753"
    #グラフ中の次のVについて
    for n in num:
        next_v = v + n
        # 探索打ち切り条件->
        # すでに探索済み or なにかの終了条件に引掛かる
        if int(next_v) > N: continue
        # 見られていない場合、再帰的に探索
        dfs(next_v)
        if "3" in next_v and "5" in next_v and "7" in next_v:
            cnt += 1

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

def dfs(i):
    global ans
    if int(i) > N:
        return
    if all(i.count(c) for c in '753'):
        ans += 1
    dfs(i + '3')
    dfs(i + '5')
    dfs(i + '7')
    
dfs('0')

print(ans)

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

def dfs(s):
    global ans
    if int(s) > N:
        return

    if s.count('7') and s.count('5') and s.count('3'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)
# Original solution
n = int(eval(input()))

ans = 0
t = [3, 5, 7]
while len(t) > 0:
    x = t.pop(0)
    if x * 10 + 3 <= n:
        t.append(x * 10 + 3)
        if x * 10 + 5 <= n:
            t.append(x * 10 + 5)
            if x * 10 + 7 <= n:
                t.append(x * 10 + 7)
    if 357 <= x <= n:
        s = str(x)
        if '3' in s and '5' in s and '7' in s:
            ans += 1
print(ans)


# Optimized solution
# https://img.atcoder.jp/abc114/editorial.pdf
N = int(eval(input()))


def dfs(s):  # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0  # s 自体が七五三数なら +1
    for c in '753':
        ret += dfs(s + c)
    return ret


print((dfs('0'))) # 本当は dfs('') と書きたいが 6 行目でのエラーを防ぐため仕方なく
# Original solution
# 解説放送
def check(var):
    in_range = var <= N
    all_num_in = all(c in str(var) for c in '753')
    return in_range and all_num_in


def dfs(x):
    res = 0
    if check(x):
        res += 1
    if x <= N:
        res += dfs(10 * x + 3)
        res += dfs(10 * x + 5)
        res += dfs(10 * x + 7)
    return res


N = int(eval(input()))
print((dfs(0)))


# Optimized solution
# 解説放送
def dfs(x):
    if x > N: return 0
    res = 1 if all(c in str(x) for c in '753') else 0
    for v in 3, 5, 7:
        res += dfs(10 * x + v)
    return res


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


def to753(q):
    q, r = divmod(q, 4)
    r = 0 if r == 0 else 2 * r + 1  # 1->3, 2->5, 3->7
    if q == 0:
        return str(r)
    else:
        return to753(q) + str(r)


ans = 0
for qt in range(1, 4 ** 9):
    s = to753(qt)
    # print(qt, list(s))
    if '0' in s: continue
    if int(s) > N: break
    if all(c in s for c in '753'): ans += 1
print(ans)


# Optimized solution
# x以降のグラフの753数
def dfs(x):
    if x > N: return 0
    res = 1 if all(c in str(x) for c in '753') else 0  # x自身が753数かどうか
    for v in 3, 5, 7:
        res += dfs(10 * x + v)
    return res


N = int(eval(input()))
print((dfs(0)))
# Original solution
def check(var):
    in_range = var <= N
    all_num_in = all(c in str(var) for c in '753')
    return in_range and all_num_in


def dfs(x):
    res = 0
    if check(x):
        res += 1
    if x <= N:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


N = int(eval(input()))
print((dfs(0)))


# Optimized solution
def check(var):
    return (0 <= var <= N) and all(c in str(var) for c in '753')


def dfs(x):
    res = 0
    if check(x): res += 1
    if x <= N:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


N = int(eval(input()))
print((dfs(0)))
# Original solution
def check(var):
    return (0 <= var <= N) and all(c in str(var) for c in '753')


def dfs(x):
    res = 0
    if check(x): res += 1
    if x <= N:
        for v in 3, 5, 7:
            res += dfs(10 * x + v)
    return res


N = int(eval(input()))
print((dfs(0)))


# Optimized solution
def dfs(s):
    res = 0
    if int(s) > N: return res
    if all(c in s for c in '753'): res += 1
    for v in '753': res += dfs(s + v)
    return res


N = int(eval(input()))
print((dfs('0')))
# Original solution
def func(var):
    res = 1 if all(c in str(var) for c in '357') else 0
    if var > N:
        return 0
    else:
        for v in 3, 5, 7:
            res += func(var * 10 + v)
    return res


N = int(eval(input()))
res = 0
for v in 3, 5, 7:
    res += func(v)
print(res)


# Optimized solution
def rec(s):
    """引数末尾に753を付け加えてできる753数
    753以外の数が現れないように文字を加えているので、
    ・すべて一回以上出たら753数に加算
    ・Nを超えたらreturn 0
    させればよい"""
    # base case
    if int(s) > n:
        return 0

    res = 0
    if all(c in s for c in '753'):
        res += 1

    # 再帰ステップ
    for c in '753':
        res += rec(s + c)
    return res


n = int(eval(input()))
print((rec('0')))
# 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 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
    else:
        ret = 0
    for c in "753":
        ret += dfs(s + c)
    return ret

print((dfs("0")))
# Original solution
def sigm(nk):
    s=3**3*(3**(nk-2)-1)/(3-1)
    s=s-3*2**3*(2**(nk-2)-1)/(2-1)
    s=s+(nk-2)*3
    return int(s)
    
n=int(eval(input()))

if n<357:
    print((0))
else:
    x0=[357,375,537,573,735,753]
    x1=[3,5,7]
    m=0
    nk=len(str(n))
    if nk==3:
        for j in range(6):
            x=x0[j] 
#            print(x)
            if x<=n:
                m=m+1
    else:
        m=sigm(nk-1)
        for i in range(3**nk):
            ii=i
            x=0
            for j in range(nk):
                iii=ii//3
                ir=ii-iii*3
                ii=(ii-ir)//3
                x=x+int(x1[ir])*10**j
            xstr=str(x)
            if xstr.find("3")>=0 and xstr.find("5")>=0 and xstr.find("7")>=0 and n>=x:
                m=m+1                 
    print(m)


# Optimized solution

import itertools

n=int(eval(input()))

kn=len(str(n))

icnt=0
for kkn in range(3,kn+1):
    for i in itertools.product([3,5,7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
            ni=0
            for ii in i:
                ni=ni*10+ii
#            print("1:",i,ni)
            if ni<=n:
                icnt+=1    
print(icnt)
# Original solution
n=int(eval(input()))
option=[3,5,7]
completed=[]
a=[3,5,7]
ans=0
while option:
    number=option.pop()
    completed.append(number)
    for add_number in a:
        new_number=number*10+add_number
        if new_number<=n:
            option.append(new_number)
for i in completed:
    i=list(str(i))
    i=set(i)
    if len(set(i))==3:
        ans+=1
print(ans)

# Optimized solution
n=int(eval(input()))
import itertools as it

ans=0
for i in range(3,len(str(n))+1):
    pr=list(it.product("753",repeat=i))
    
    for j in pr:
        s=set(j)
        if len(s)==3:
            num=int(''.join(j))
            if num<=n:
                ans+=1
print(ans)
# Original solution
N=int(eval(input()))

ans = 0
def dfs(s, sum):
  global ans
  sum = sum + s


  if int(sum) > N:
    return False

  sum = str(int(sum))
  if sum.count("3") >= 1 and sum.count("5") >= 1 and sum.count("7") >= 1:
    ans += 1
  
  if dfs("3", sum):
    return True
  
  if dfs("5", sum):
    return True
  
  if dfs("7", sum):
    return True
  
  
dfs("0" ,'')
print(ans)

  

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

ans = 0
def dfs(s, target):
  global ans
  target = target + s

  if int(target) > N:
    return False

  if target.count("3") >= 1 and target.count("5") >= 1 and target.count("7") >= 1:
    ans += 1
  
  if dfs("3", target):
    return True
  
  if dfs("5", target):
    return True
  
  if dfs("7", target):
    return True
  
  
dfs("0" ,'')
print(ans)
# Original solution
# -*- coding: utf-8 -*-

from itertools import product

N = int(eval(input()))

cnt = 0
# 候補となりうる10桁までの数字を列挙
for prod in product(['0', '3', '5', '7'], repeat=10):
    # チェック用に変形
    num = int(''.join(prod))
    s = str(num)
    # 753数ではない
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    # N以下ではない
    if num > N:
        continue
    cnt += 1
print(cnt)


# Optimized solution
# -*- coding: utf-8 -*-

from itertools import product

N = int(eval(input()))

cnt = 0
# 候補となりうる9桁までの数字を列挙
for prod in product(['0', '3', '5', '7'], repeat=9):
    # チェック用に変形
    num = int(''.join(prod))
    s = str(num)
    # 753数ではない
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    # N以下ではない
    if num > N:
        continue
    cnt += 1
print(cnt)
# Original solution
# -*- coding: utf-8 -*-

from itertools import product

N = int(eval(input()))

cnt = 0
# 候補となりうる9桁までの数字を列挙
for prod in product(['0', '3', '5', '7'], repeat=9):
    # チェック用に変形
    num = int(''.join(prod))
    s = str(num)
    # 753数ではない
    if (s.find('3') == -1 or s.find('5') == -1
            or s.find('7') == -1 or s.find('0') != -1):
        continue
    # N以下ではない
    if num > N:
        continue
    cnt += 1
print(cnt)


# Optimized solution
# -*- coding: utf-8 -*-

"""
解説参考
再帰関数で候補の数を作っていく版
"""

N = int(eval(input()))

def dfs(s):
    # N以下しかやらない
    if int(s) > N:
        return 0
    # 753数かどうか
    if '7' in s and '5' in s and '3' in s:
        res = 1
    else:
        res = 0
    # sの後ろに753を付けたもので再帰していく
    for c in '753':
        res += dfs(s + c)
    # 最終的に自分より大きい桁で増えた分を返却していく
    return res

print((dfs('0')))
# 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 '357') else 0
    for c in '357':
        ret += dfs(s + c)
    return ret

print((dfs('0')))

# Optimized solution
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = 0
digit = len(str(N))
# 3, 5, 7だけでできた数を列挙
for d in range(3, digit+1):
    for x in itertools.product(['3', '5', '7'], repeat=d):
        if len(set(x)) != 3:
            continue
        y = int(''.join(x))
        if y <= N:
            answer += 1

print(answer)
# Original solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def LIST()  : return list(MAP())

n = INT()
ans = 0
for x in product([0, 3, 5, 7], repeat=9):
    y = 0
    for i in range(9):
        y += x[8-i] * 10**i
    if y > n:
        break
    if str(y).count('0') == 0 and x.count(3) > 0 and x.count(5) > 0 and x.count(7) > 0:
        ans += 1
print(ans)

# Optimized solution
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(eval(input()))
def MAP()   : return list(map(int,input().split()))
def LIST()  : return list(MAP())

n = INT()

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')))
# Original solution
import itertools
from collections import defaultdict

N=input()
k=len(N)

if int(N)<357:
	print(0)
	quit()

ans=0

for k in range(3,k+1):
	L=list(itertools.product( (3,5,7) , repeat=k))

	for t  in L:
		C=defaultdict(lambda: 0)
		v=0

		for idx, x in enumerate(t):
			v+=x*(10**idx)
			if x!=0:
				C[x]+=1
	
		if v<=int(N) and len(C)==3:
			ans+=1

print(ans)



# Optimized solution
N=eval(input())

l=len( str(N) )

s="357"

P=[ set() for i in range(l+1) ]   #Pattern
P[0].add(0)

for i in range(1,l+1):
	k=l-i	#keta
	for x in P[i-1]:
		for j in s:
			j=int(j)
			P[i].add(  x+(10**k)*j )
			P[i].add( 0 )


ans=0
for x in P[-1]:
	if  1<= x <= N:
		for i in s:
			if i not in str(x):
				break
		else:
			ans+=1

print(ans)
# Original solution
from itertools import product
from bisect import bisect_left, bisect_right

n = int(eval(input()))
s = []
for i in range(3, 10):
    for v in product('753', repeat=i):
        if len(set(v)) >= 3:
            s.append(int(''.join(v)))

s.sort()

idx = bisect_right(s, n)
print((len(s[:idx])))

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

def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)

A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)

cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)
# Original solution
n = int(eval(input()))

def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)

A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)

cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)

# Optimized solution
# 7/3

# n 以下の「753数」の個数

n = int(eval(input()))

def dfs(val):
    # 終了条件
    if val > n:
        return

    A.append(val)

    for v in [3, 5, 7]:
        val = A.pop()
        dfs(10 * val + v)
        A.append(val)

A = []
for v in [3, 5, 7]:
    dfs(v)

res = 0
for v in A:
    s = str(v)
    if '3' in s and '5' in s and '7' in s:
        res += 1

print(res)
# Original solution
def dfs(s,n):
    if int(s)>n:
        return 0
    cur = 0
    if all(s.count(c) > 0 for c in '753'):
        cur = 1
    for c in "753":
        cur += dfs(s+c,n)
    return cur
def examC():
    N = I()
    ans = dfs("0",N)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


# Optimized solution
def examA():
    N, M = LI()
    l = 1; r = N
    for _ in range(M):
        L, R = LI()
        l = max(L,l)
        r = min(R,r)
    ans = max(0,r-l+1)
    print(ans)
    return

def examB():
    N = I()
    S = [I()for _ in range(N)]
    rest = []
    for s in S:
        if s%10==0:
            continue
        rest.append(s)
    if sum(S)%10==0:
        if not rest:
            print((0))
            return
        ans = sum(S) - min(rest)
    else:
        ans = sum(S)
    print(ans)
    return

def examC():
    N, K = LI()
    K -= 1
    A = LI()
    L = A.index(1)
    #print(L)
    ans = (N-1+K-1)//K
    print(ans)
    return

def examD():
    def ketadp(a):
        n = len(a)
        dp = defaultdict(int)
        dp[0, 0, 0, 0, 0] = 1
        for i, less, has3, has5, has7 in itertools.product(list(range(n)), (0, 1), (0, 1), (0,1), (0,1)):
            max_d = 7 if less else int(a[i])
            for d in range(max_d + 1):
                if d==0 and has3==0 and has5==0 and has7==0:
                    dp[i + 1, 1, has3, has5, has7] += dp[i, less, has3, has5, has7]
                if not (d==3 or d==5 or d==7):
                    continue
                less_ = less or d < max_d
                has3_ = has3 or d == 3
                has5_ = has5 or d == 5
                has7_ = has7 or d == 7
                dp[i + 1, less_, has3_, has5_, has7_] += dp[i, less, has3, has5, has7]

        ans = sum(dp[n, less, 1, 1, 1] for less in (0, 1))
        return ans
    N = SI()
    ans = ketadp(N)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""
# Original solution
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import deque

def main():
    n = II()
    cnt = 0
    dq = deque(['3', '5', '7'])
    while dq:
        d = dq.popleft()
        if int(d) > n: break
        if '7' in d and '5' in d and '3' in d:
            cnt += 1
        dq.append(d+'3')
        dq.append(d+'5')
        dq.append(d+'7')
    print(cnt)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())

def main():
    n = II()
    def dfs(cur, use):
        counter = 0
        def dfs_(cur, use):
            nonlocal counter
            if cur > n:      return None
            if use == 0b111: counter += 1
            dfs_(cur*10 + 7, use | 0b001)
            dfs_(cur*10 + 5, use | 0b010)
            dfs_(cur*10 + 3, use | 0b100)
        dfs_(cur, use)
        return counter
    print((dfs(0, 0)))

if __name__ == '__main__':
    main()
# Original solution
num = int(eval(input()))
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
c = ["3","5","7"]
ch = ["0","3","5","7"]
ans = 0
for i in range(4 ** len(str(num))):
  s = to3(i,4)
  ss = ""
  for j in range(len(s)):
    ss += ch[int(s[j])]
  key = 1
  k1 = 0
  k2 = 0
  k3 = 0
  for k in range(len(ss)):
    if ss[k] == "0":
      key = 0
      break
    elif ss[k] == "3":
      k1 = 1
    elif ss[k] == "5":
      k2 = 1
    else:
      k3 = 1
  if key == 1 and k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)

# Optimized solution
num = int(eval(input()))
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
ch = ["3","5","7"]
ans = 0
for i in range(3 ** len(str(num))+1):
  s = to3(i,3)
  for u in range(len(str(num))-len(s)+2):
    if u > 0:
      s = "0" + s
    k1 = 0
    k2 = 0
    k3 = 0
    ss = ""
    for j in range(len(s)):
      if s[j] == "0":k1 = 1
      elif s[j] == "1":k2 = 1
      else: k3 = 1
      ss += ch[int(s[j])]
    if k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)