N = int(eval(input()))



def check_753(s):

  s = str(int(s))

  a = ''.join(sorted(list(set(s))))

  if a == '357':

    return True

  else:

    return False



def shi(s):

  if int(s) > N:

    return 0

  if check_753(s):

    ret = 1

  else:

    ret = 0

  for i in '753':

    ret += shi(s+i)

  return ret



print((shi('0')))

import itertools as t



N = int(eval(input()))



L = [ int(''.join(j)) for i in range(10) for j in t.product(['3','5','7'], repeat=i) if '3' in j and '5' in j and '7' in j]

L = [i for i in L if i <= N]

print((len(L)))

N = int(eval(input()))


def check_753(s):
    s = str(int(s))
    a = "".join(sorted(list(set(s))))
    if a == "357":
        return True
    else:
        return False


def shi(s):
    if int(s) > N:
        return 0
    if check_753(s):
        ret = 1
    else:
        ret = 0
    for i in "753":
        ret += shi(s + i)
    return ret


print((shi("0")))

import itertools as t

N = int(eval(input()))
L = [
    int("".join(j))
    for i in range(10)
    for j in t.product(["3", "5", "7"], repeat=i)
    if "3" in j and "5" in j and "7" in j
]
L = [i for i in L if i <= N]
print((len(L)))

+import itertools as t + - - -def check_753(s): -    s = str(int(s)) -    a = "".join(sorted(list(set(s)))) -    if a == "357": -        return True -    else: -        return False - - -def shi(s): -    if int(s) > N: -        return 0 -    if check_753(s): -        ret = 1 -    else: -        ret = 0 -    for i in "753": -        ret += shi(s + i) -    return ret - - -print((shi("0"))) +L = [ +    int("".join(j)) +    for i in range(10) +    for j in t.product(["3", "5", "7"], repeat=i) +    if "3" in j and "5" in j and "7" in j +] +L = [i for i in L if i <= N] +print((len(L)))