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)))
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")))
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)))

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")))

-def dfs(s, num): -    if int(s) > num: +n = int(eval(input())) + + +def dfs(now): +    if int(now) > n: -    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0: +    for i in "753": +        if i not in now: +            ret = 0 +            break +    else: -    else: -        ret = 0 -        ret += dfs(s + i, num) +        ret += dfs(now + i) -n = int(eval(input())) -print((dfs("0", n))) +print((dfs("0")))