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')))
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)





def main():

    N = int(eval(input()))



    def dfs(s):

        if int(s) > N:

            return 0

        ret = 1 if all(s.count(c) for c in '357') else 0

        for c in '357':

            ret += dfs(s+c)

        return ret



    print((dfs('0')))





if __name__ == '__main__':

    main()

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

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    N = int(eval(input()))

    def dfs(s):
        if int(s) > N:
            return 0
        ret = 1 if all(s.count(c) for c in "357") else 0
        for c in "357":
            ret += dfs(s + c)
        return ret

    print((dfs("0")))


if __name__ == "__main__":
    main()

-n = int(eval(input())) +import sys + +input = sys.stdin.readline +sys.setrecursionlimit(10**7) -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 +def main(): +    N = int(eval(input())) + +    def dfs(s): +        if int(s) > N: +            return 0 +        ret = 1 if all(s.count(c) for c in "357") else 0 +        for c in "357": +            ret += dfs(s + c) +        return ret + +    print((dfs("0"))) -print((dfs("0"))) +if __name__ == "__main__": +    main()