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)



  
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)



  
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)

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)

-def dfs(s, sum): +def dfs(s, target): -    sum = sum + s -    if int(sum) > N: +    target = target + s +    if int(target) > N: -    sum = str(int(sum)) -    if sum.count("3") >= 1 and sum.count("5") >= 1 and sum.count("7") >= 1: +    if target.count("3") >= 1 and target.count("5") >= 1 and target.count("7") >= 1: -    if dfs("3", sum): +    if dfs("3", target): -    if dfs("5", sum): +    if dfs("5", target): -    if dfs("7", sum): +    if dfs("7", target):