CodeEff/ECCO huggingface dataset:
# Original solution
def resolve():
    from collections import deque
    n = int(eval(input()))
    ans = 0
    num = deque([3,5,7])
    while num[0] <= n:
        test = num.popleft()
        num.append(test * 10 + 3)
        num.append(test * 10 + 5)
        num.append(test * 10 + 7)
        if list(set([int(x) for x in list(str(test))])) == [3,5,7]:
            ans += 1
    print(ans)

resolve()

# Optimized solution
def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i== "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(eval(input()))
    if n < 357:
        print((0))
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a*10+3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
        print(ans)
resolve()
# Original solution
import copy

word = "753"


def dfs(n):
    ret = 0

    num = 0 if not n else int(''.join(n))

    if N < num:
        return ret

    ret += 1 if len(set(''.join(n)) & set(word)) == len(word) else 0

    for c in word:
        tmp = copy.deepcopy(n)
        n.append(c)
        ret += dfs(n)
        n = tmp

    return ret


N = int(eval(input()))

print((dfs([])))


# Optimized solution
ans = 0


def dfs(n, f1, f2, f3):
    if N < n:
        return

    global ans
    ans += 1 if f1 & f2 & f3 else 0

    dfs(n * 10 + 7, True, f2, f3)
    dfs(n * 10 + 5, f1, True, f3)
    dfs(n * 10 + 3, f1, f2, True)


N = int(eval(input()))

dfs(0, False, False, False)

print(ans)
# Original solution
def f(n, f1, f2, f3):
    ret = 0

    def dfs(n, f1, f2, f3):
        if N < n:
            return 0

        nonlocal ret
        ret += 1 if f1 and f2 and f3 else 0

        dfs(n * 10 + 7, True, f2, f3)
        dfs(n * 10 + 5, f1, True, f3)
        dfs(n * 10 + 3, f1, f2, True)

        return ret

    return dfs(n, f1, f2, f3)


N = int(eval(input()))

print((f(0, False, False, False)))


# Optimized solution
def dfs(ret, cur, f1, f2, f3):
    if N < cur:
        return ret

    ret += 1 if f1 and f2 and f3 else 0

    ret = dfs(ret, cur * 10 + 7, True, f2, f3)
    ret = dfs(ret, cur * 10 + 5, f1, True, f3)
    ret = dfs(ret, cur * 10 + 3, f1, f2, True)

    return ret


N = int(eval(input()))

print((dfs(0, 0, False, False, False)))
# Original solution
# coding: utf-8
# Your code here!
N=int(eval(input()))

l=[3,5,7]
l_ans=[]
l_ans+=l

if N<357:
    print((0))
else:
    for i in range(8):
        temp=[]
        for item in l:
            temp.append(item+3*10**(i+1))
            temp.append(item+5*10**(i+1))
            temp.append(item+7*10**(i+1))
        l.clear()
        l+=temp
        l_ans+=temp
    l_ans.sort()
    
    count=0
    for i in range(len(l_ans)):
        if l_ans[i]>N:
            break
        elif  ("3" in str(l_ans[i]) and "5" in str(l_ans[i]) and "7" in str(l_ans[i]))==False:
            pass
        else:
            count+=1
            
    print(count)

# Optimized solution
# coding: utf-8
# Your code here!
N=int(eval(input()))


cand=[]
def saiki(num,arc):
    if "3" in arc and "5" in arc and "7" in arc:
        cand.append(arc)
    if num==len(str(N)):
        return 0
    else:
        for item in ["3","5","7"]:
            saiki(num+1,arc+[item])
    return 0


saiki(0,[])

ans=0
for item in cand:
    if N>=((int("".join(item)))):
        ans+=1
        
print(ans)
# Original solution
N = int(eval(input()))
M = len(str(N))

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

res = 0
for m in range(3,M+1):
    for i in range(3 ** m):
        tri = nsin(i, 3).zfill(m)
        nl = []
        if tri.count('0') > 0 and tri.count('1') > 0 and tri.count('2') > 0:
            for j in range(m):
                if tri[j] == '0':
                    nl.append('3')
                elif tri[j] == '1':
                    nl.append('5')
                else:
                    nl.append('7')
            x = ''.join(nl)
            if int(x) <= N:
                res += 1

print(res)


# Optimized solution
N = int(eval(input()))
M = len(str(N))
res = [0]
def dfs(x):
    # 長さがMになったら終了
    if len(x) > M:
        return
    if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0 and int(x) <= N:
        res[0] += 1
    dfs(x + '3')
    dfs(x + '5')
    dfs(x + '7')
    return

dfs('3')
dfs('5')
dfs('7')
print((res[0]))
# Original solution
n = int(eval(input()))

def tobase4(num):
    ans = ''
    while num>0:
        ans += str(num%4)
        num //= 4
    return ans[::-1]

def check(s):
    if '1' in s and '2' in s and '3' in s and '0' not in s:
        return True
    return False

def conv(s):
    s = s.replace('2','5')
    s = s.replace('3','7')
    s = s.replace('1','3')
    return s

res = 0
for i in range(10**9):
    s = tobase4(i)
    if not check(s):
        continue
    s = conv(s)
    s = int(s)
    #print(s)
    if n < s:
        break
    #print(s)
    res += 1
print(res)


# Optimized solution
def dfs(N,s,a,b,c):
    if int(s)>N:
        return 0
    ret  = dfs(N,s+'3',True,b,c)
    ret += dfs(N,s+'5',a,True,c)
    ret += dfs(N,s+'7',a,b,True)
    return ret + (a and b and c)

print((dfs(int(eval(input())),'0',False,False,False)))
# Original solution
N = int(eval(input()))
array = []
for i in range(10**9):
    res = ''
    digit = 0
    while i:
        res = '0357'[i % 4] + res
        i //= 4
    if '3' in res and '5' in res and '7' in res and '0' not in res:
        res = int(res)
        if res > 10 ** 9:
            break
        array += [res]
array += [10**9]
for i in range(len(array)):
    if array[i] > N:
        print(i)
        exit()


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


def resol_a(x, a):
    if x < 10:
        return int(x >= a)
    d = 0
    while x > 10**(d+1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    c = resol_a(r, a)
    b = resol_a(10 ** d - 1, a)
    bb = resol_a(10 ** (d - 1), a)
    if f > a:
        return b + 1
    elif f == a:
        return b + c - bb
    else:
        return b


def resol_ab(x, a, b):
    d = 0
    if x < 100:
        return (x >= 10 * b + a) + (x >= 10 * a + b)
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_ab((a+1)*10**d-1, a, b)
    elif f == a:
        return resol_ab(a * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, b) - resol_a(10 ** (d - 1), b), 0)
    elif f > b:
        return resol_ab((b+1)*10 ** d - 1, a, b)
    elif f == b:
        return resol_ab(b * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, a) - resol_a(10 ** (d - 1), a), 0)
    else:
        return resol_ab(10 ** d - 1, a, b)


def resol_abc(x, a, b, c):
    if x < 1000:
        A, B, C = str(a), str(b), str(c)
        return sum([x >= int(_) for _ in [A+B+C, A+C+B, B+A+C, B+C+A, C+A+B, C+B+A]])
    d = 0
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_abc((a+1)*10**d-1, a, b, c)
    elif f == a:
        return resol_abc(a*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, b, c)-resol_ab(10**(d-1), b, c), 0)
    elif f > b:
        return resol_abc((b+1)*10**d-1, a, b, c)
    elif f == b:
        return resol_abc(b*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, c)-resol_ab(10**(d-1), a, c), 0)
    elif f > c:
        return resol_abc((c+1)*10**d-1, a, b, c)
    elif f == c:
        return resol_abc(c*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, b)-resol_ab(10**(d-1), a, b), 0)
    else:
        return resol_abc(10**d-1, a, b, c)


print((resol_abc(N, 7, 5, 3)))
# Original solution
N = int(eval(input()))


def resol_a(x, a):
    if x < 10:
        return int(x >= a)
    d = 0
    while x > 10**(d+1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    c = resol_a(r, a)
    b = resol_a(10 ** d - 1, a)
    bb = resol_a(10 ** (d - 1), a)
    if f > a:
        return b + 1
    elif f == a:
        return b + c - bb
    else:
        return b


def resol_ab(x, a, b):
    d = 0
    if x < 100:
        return (x >= 10 * b + a) + (x >= 10 * a + b)
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_ab((a+1)*10**d-1, a, b)
    elif f == a:
        return resol_ab(a * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, b) - resol_a(10 ** (d - 1), b), 0)
    elif f > b:
        return resol_ab((b+1)*10 ** d - 1, a, b)
    elif f == b:
        return resol_ab(b * 10 ** d - 1, a, b) + max(resol_ab(r, a, b) - resol_ab(10 **
                                                                                  (d - 1), a, b), 0) + max(resol_a(r, a) - resol_a(10 ** (d - 1), a), 0)
    else:
        return resol_ab(10 ** d - 1, a, b)


def resol_abc(x, a, b, c):
    if x < 1000:
        A, B, C = str(a), str(b), str(c)
        return sum([x >= int(_) for _ in [A+B+C, A+C+B, B+A+C, B+C+A, C+A+B, C+B+A]])
    d = 0
    while x > 10 ** (d + 1):
        d += 1
    f = x // 10 ** d
    r = x % 10 ** d
    if f > a:
        return resol_abc((a+1)*10**d-1, a, b, c)
    elif f == a:
        return resol_abc(a*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, b, c)-resol_ab(10**(d-1), b, c), 0)
    elif f > b:
        return resol_abc((b+1)*10**d-1, a, b, c)
    elif f == b:
        return resol_abc(b*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, c)-resol_ab(10**(d-1), a, c), 0)
    elif f > c:
        return resol_abc((c+1)*10**d-1, a, b, c)
    elif f == c:
        return resol_abc(c*10**d-1, a, b, c)+max(resol_abc(r, a, b, c)-resol_abc(10**(d-1), a, b, c), 0)+max(resol_ab(r, a, b)-resol_ab(10**(d-1), a, b), 0)
    else:
        return resol_abc(10**d-1, a, b, c)


print((resol_abc(N, 7, 5, 3)))

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


def dfs(x, a, b, c):
    if x > N:
        return 0
    else:
        return all([a, b, c]) + dfs(x * 10 + 7, a, b, 1) + dfs(x * 10 + 5, a, 1, c) + dfs(x * 10 + 3, 1, b, c)


print((dfs(0, 0, 0, 0)))
# Original solution
import copy
n = int(eval(input()))
ans = 0
for i in range(2,10):
  list = ["3","5","7"]
  for j in range(i):
    dlist = []
    for k in list:
      for l in ("3","5","7"):
        dlist.append(k+l)
    list = copy.copy(dlist)
  for m in list:
    if "3" in m and "5" in m and "7" in m:
      if int(m) <= n:
        ans +=1
      else:
        print(ans)
        exit()

# Optimized solution
n = int(eval(input()))
ans = 0
def dfs(m):
  global ans
  if m > n:
    return
  sm = str(m)
  if "3" in sm and "5" in sm and "7" in sm:
    ans += 1
  dfs(m*10+3)
  dfs(m*10+5)
  dfs(m*10+7)
dfs(0)
print(ans)
# Original solution
def is_753(n):
    n = str(n)
    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)


n = int(eval(input()))


v = [7, 5, 3]
li = []
prev = [7, 5, 3]

for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

print((len(li)))

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

N = int(eval(input()))
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print((len(li)))
# 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
ans = 0
def dfs(x, a, b, c):
    global ans
    if x > N : return
    if a & b & c: ans += 1
    dfs(10*x+3, 1, b, c)
    dfs(10*x+5, a, 1, c)
    dfs(10*x+7, a, b, 1)

N = int(eval(input()))

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

from functools import lru_cache
@lru_cache(maxsize=1000)
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": #文字列数値をforで回すときの書き方！ 覚える
        ret += dfs(s+c) #pythonなのでそのまま+できる
    return ret

print((dfs("0")))

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

#from functools import lru_cache
#@lru_cache(maxsize=1000)
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": #文字列数値をforで回すときの書き方！ 覚える
        ret += dfs(s+c) #pythonなのでそのまま+できる
    return ret

print((dfs("0")))
# Original solution

#abc114-C:dfs

n=int(eval(input()))

def dfs(s):
    #s>nになったら数えない
    if int(s)>n:
        return 0

    #7,5,3がすべて入ってたら1,それ以外は0を返す変数を考える
    cnt=1 if all(s.count(c)>0 for c in '753') else 0

    for c in '753':
        cnt+=dfs(s+c)

    return cnt

print((dfs('0')))

# Optimized solution
n = int(eval(input()))
def dfs(string):
    if len(string) == len(str(n)):
        return 1 if all(k in string for k in '753') and int(''.join(string)) <= n else 0

    rec = 0
    s = '753' if len(string) != 0 and string[-1] != '0' else '0753'
    for num in s:
        string.append(num)
        rec += dfs(string)
        string.pop()

    return rec

print((dfs([])))
# Original solution
from bisect import  bisect

def convert(number) :
    if number == 0 :
        out = "0"
    else :
        out = ""
    while number > 0 :
        surplus = (number % 4)
        out = str(surplus) + out
        number //= 4
    return out

def seven_five_three(string) :
    string = string.replace("3","7").replace("2","5").replace("1","3")
    return string

L = []
for i in range(3*10**5) :
    l = convert(i)
    l = seven_five_three(l)
    if (("0" in l) or ("3" not in l) or ("5" not in l) or ("7" not in l)) :
        continue
    l = int(l)
    L.append(l)

N = int(eval(input()))
ans = bisect(L,N)
print(ans)


# Optimized solution
from itertools import product
element = [3,5,7]

N = int(eval(input()))
ans = 0
for i in range(3, len(str(N)) + 1) :
    L = product(element, repeat=i)
    for candidate in L :
        if ((3 not in candidate) or (5 not in candidate) or (7 not in candidate)) :
            continue
        l = int("".join(list(map(str,candidate))))
        if l <= N :
            ans += 1
print(ans)
# Original solution
from itertools import product
N = int(eval(input()))
E = [3,5,7]
ans = 0

for i in range(3, len(str(N))+1) :
    L = product(E, repeat=i)
    for l in L :
        if (3 not in l) or (5 not in l) or (7 not in l) :
            continue
        number = int("".join(list(map(str,l))))
        if number <= N :
            ans += 1
print(ans)


# Optimized solution
from itertools import *

N = int(eval(input()))

A = ["3", "5", "7"]

ans = 0

length = len(str(N))

for i in range(3, length+1) :
    for prod in product(A, repeat=i) :
        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0 :
            continue
        
        num = int("".join(prod))
        if num > N :
            break
        
        ans += 1
        
print(ans)
# Original solution
import itertools
N = int(eval(input()))
cnt = 0
for i in range(1,11):
  for v in itertools.product('357', repeat = i):
    p = "".join(v)
    if('3' in v and '5' in v and '7' in v and int(p) <= N):
      cnt += 1
print(cnt)

# Optimized solution
from itertools import product

N = int(eval(input()))

ans = 0
for i in range(1,11):
  for fst in product(['5','7','3'], repeat = i):
    num = "".join(fst)
    if('5' in num and '7' in num and '3' in num and int(num) <= N):
      ans += 1
print(ans)
# Original solution
from itertools import product

def ans():
  N = int(eval(input()))
  cnt = 0
  for i in range(3, 11):
    for p in product(["3", "5", "7"], repeat = i):
      if("3" in p and "5" in p and "7" in p):
        p = int("".join(p))
        if(p <= N):
          cnt += 1
  print(cnt)
ans()

# 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(["3", "5", "7"], repeat = i):
    if("3" in p and "5" in p and "7" in p):
      if(int("".join(p)) <= N):
        cnt += 1
print(cnt)
# Original solution
import sys
sys.setrecursionlimit(100000)
n=int(eval(input()))
m=len(str(n))
L=[]
def dfs(i,num):
    if i==m+1:
        return
    if 0<i<m+1:
        if len(set(num))==3 and int(num)<=n:
            L.append(int(num))
    dfs(i+1,num+'3')
    dfs(i+1,num+'5')
    dfs(i+1,num+'7')
dfs(0,'')
print((len(L)))

# Optimized solution
n=int(eval(input()))
m=len(str(n))
r=0

def dfs(i,s):
    global r
    if len(set(s))==3 and int(s)<=n:
        r+=1
    if i==m:
        return
    dfs(i+1,'3'+s)
    dfs(i+1,'5'+s)
    dfs(i+1,'7'+s)

dfs(0,'')
print(r)
# Original solution
# 2019/08/27

n=int(eval(input()))
ln=len(str(n))
sft='7530'
cnt=0
def dfs(ln,s):
    global cnt
    if ln==0:
        if '7' in s and '5' in s and '3' in s:
            if '0' in str(int(s)):return
            if n>=int(s):cnt+=1
        return
    for e in sft:
        dfs(ln-1,s+e)
dfs(ln,'')

print(cnt)

# Optimized 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')))
# Original solution
import itertools
N=int(eval(input()))
ans=0
S=[]
for i in range(10):
    S+=list(itertools.product("357",repeat=i))
for s in S:
    if len(set(s))>2 and int("".join(s))<=N:
        ans+=1
print(ans)

# Optimized solution
from itertools import product
N = int(eval(input()))
count = 0
for i in range(3,10):
    a = product(["3","5","7"],repeat=i)
    for b in a:
        if 1<=int("".join(b))<=N and len(set(b))==3:
            count += 1
print(count)
# Original solution
import itertools
N=int(eval(input()))
l=len(str(N))
s=set()
S='753'
for i in range(1,l+1):
    for j in itertools.product(S,repeat=i):
        s.add(int(''.join(j)))
li=sorted(s)
cnt=0
for i in range(len(li)):
    if(li[i]>N):
        break
    if('7' in str(li[i]) and '5' in str(li[i]) and '3' in str(li[i])):
        cnt+=1
print(cnt)

# Optimized solution
c='753'
def dfs(s,L):
    global c
    li.append(s)
    if(len(s)==L):
        return
    for i in range(3):
        dfs(s+c[i],L)

N=int(eval(input()))
L=len(str(N))
li=[]
dfs('',L)
ans=0
for x in li:
    if(x==''):
        continue
    if(int(x)<=N and '7' in x and '5' in x and '3' in x):
        ans+=1
print(ans)
# Original solution
import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    stack = deque(["3", "5", "7"])
    num = 0
    while stack:
        n = stack.pop()
        if int(n) > N:
            continue
        num += 1 if all(s in n for s in "357") else 0
        stack.append("3" + n)
        stack.append("5" + n)
        stack.append("7" + n)
    return num


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

    ans = dfs(N)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
from collections import deque

input = sys.stdin.readline


def bfs(N):
    res = 0
    queue = deque(["3", "5", "7"])
    while queue:
        num = queue.popleft()
        if int(num) > N:
            break
        if all(("3" in num, "5" in num, "7" in num)):
            res += 1
        queue.append("".join([num, "3"]))
        queue.append("".join([num, "5"]))
        queue.append("".join([num, "7"]))
    return res


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

    ans = bfs(N)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

# 10 -> n
def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=I()

  l=[]
  for i in range(pow(4,10)):
    l.append(ten2n(i,4).replace('3','7').replace('2','5').replace('1','3'))

  cnt=0
  for x in l:
    if int(x)<=n:
      if '3' in x and '5' in x and '7' in x and '0' not in x:
        cnt+=1
    else:
      break

  return cnt

print((main()))


# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())

# 10 -> n
def ten2n(a,n):
  x=a//n
  y=a%n
  if x:
    return ten2n(x,n)+str(y)
  return str(y)

def main():
  n=I()

  l=[]
  for i in range(pow(4,9)):
    l.append(ten2n(i,4).replace('3','7').replace('2','5').replace('1','3'))

  cnt=0
  for x in l:
    if int(x)<=n:
      if '3' in x and '5' in x and '7' in x and '0' not in x:
        cnt+=1
    else:
      break

  return cnt

print((main()))
# Original solution
N = int(eval(input()))
import math
INF = 10**9


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


print((dfs("0")))

# Optimized solution
#!/usr/bin/env python3
import sys
import functools
import itertools
INF = float("inf")


@functools.lru_cache(maxsize=None)
def pow(b, n):
    return b**n


def f(n):
    # n桁の753数
    if n < 3:
        return 0

    return pow(3, n) - 3*pow(2, n) + 3


def solve(N: int):
    ketamax = len(str(N))

    ans = 0
    # 桁
    for i in range(3, ketamax):
        ans += f(i)
    # print(ans)
    # 最大桁数の場合だけごにょる(O(N))
    for item in itertools.product(["3", "5", "7"], repeat=ketamax):
        if "3" not in item or "5" not in item or "7" not in item:
            continue
        elif int("".join(item)) > N:
            continue
        else:
            ans += 1
    print(ans)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()
# Original solution
import copy
from collections import deque

n = int(eval(input()))

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_used = copy.deepcopy(used)
    cp_s.append(c)
    cp_used.add(c)
    d.append((cp_s,cp_used))
  
print(count)

# Optimized solution
import copy
from collections import deque

n = int(eval(input()))

ans = 0
array = ['7','5','3']

count = 0
d = deque()
d.append(([],set()))

while len(d) != 0:
  s,used = d.pop()
  if len(s) != 0 and int(''.join(s)) > n:
    continue
  
  if len(used) == 3:
    count += 1  
    
  for c in array:
    cp_s = copy.deepcopy(s)
    cp_s.append(c)    
    if len(used) == 3:
      d.append((cp_s,used))
    
    else:
      cp_used = copy.deepcopy(used)
      cp_used.add(c)
      d.append((cp_s,cp_used))
  
print(count)