n = int(eval(input()))



cnt = 0

i = 1

while i <= n:

    is_broken = False

    string = list(str(i))

    for j, s in enumerate(string):

        if s not in ['3', '5', '7']:

            i = i + 10**(len(string) - j - 1)

            is_broken = True

            break

    if is_broken:

        continue



    c1 = string.count('3') >= 1

    c2 = string.count('5') >= 1

    c3 = string.count('7') >= 1

    if c1 and c2 and c3:

        cnt += 1



    i += 1



print(cnt)
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')))
n = int(eval(input()))
cnt = 0
i = 1
while i <= n:
    is_broken = False
    string = list(str(i))
    for j, s in enumerate(string):
        if s not in ["3", "5", "7"]:
            i = i + 10 ** (len(string) - j - 1)
            is_broken = True
            break
    if is_broken:
        continue
    c1 = string.count("3") >= 1
    c2 = string.count("5") >= 1
    c3 = string.count("7") >= 1
    if c1 and c2 and c3:
        cnt += 1
    i += 1
print(cnt)

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

-cnt = 0 -i = 1 -while i <= n: -    is_broken = False -    string = list(str(i)) -    for j, s in enumerate(string): -        if s not in ["3", "5", "7"]: -            i = i + 10 ** (len(string) - j - 1) -            is_broken = True -            break -    if is_broken: -        continue -    c1 = string.count("3") >= 1 -    c2 = string.count("5") >= 1 -    c3 = string.count("7") >= 1 -    if c1 and c2 and c3: -        cnt += 1 -    i += 1 -print(cnt) + + +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")))