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'))) 
N = int(eval(input()))



def func(s, cnt):

    if int(s)>N:

        return cnt

    else:

        b=list(s)

        if '7' in b and '5' in b and '3' in b:

            cnt += 1

        for t in "753":

            cnt = func(s+t, cnt)

        return cnt

    

print((func("0", 0)))



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

N = int(eval(input()))


def func(s, cnt):
    if int(s) > N:
        return cnt
    else:
        b = list(s)
        if "7" in b and "5" in b and "3" in b:
            cnt += 1
        for t in "753":
            cnt = func(s + t, cnt)
        return cnt


print((func("0", 0)))

-def dfs(s): +def func(s, cnt): -        return 0 -    if all(s.count(c) > 0 for c in "753"): -        ret = 1 +        return cnt -        ret = 0 -    for c in "753": -        ret += dfs(s + c) -    return ret +        b = list(s) +        if "7" in b and "5" in b and "3" in b: +            cnt += 1 +        for t in "753": +            cnt = func(s + t, cnt) +        return cnt -print((dfs("0"))) +print((func("0", 0)))