import sys



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N = int(readline())



    def rec(vec):

        if vec and int(''.join(vec)) > N:

            return 0

        ans = 0

        if all(c in vec for c in '357'):

            ans += 1

        for c in '357':

            vec.append(c)

            ans += rec(vec)

            vec.pop()

        return ans



    ans = rec([])

    print(ans)

    return





if __name__ == '__main__':

    main()

import sys



read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

sys.setrecursionlimit(10 ** 9)

INF = 1 << 60

MOD = 1000000007





def main():

    N = int(readline())



    def rec(n, used):

        ans = 0

        if all(used):

            ans += 1

        for i, d in enumerate((3, 7, 5)):

            if 10 * n + d <= N:

                cur = used[i]

                used[i] = True

                ans += rec(10 * n + d, used)

                used[i] = cur

        return ans



    print((rec(0, [False, False, False])))

    return





if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(vec):
        if vec and int("".join(vec)) > N:
            return 0
        ans = 0
        if all(c in vec for c in "357"):
            ans += 1
        for c in "357":
            vec.append(c)
            ans += rec(vec)
            vec.pop()
        return ans

    ans = rec([])
    print(ans)
    return


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(n, used):
        ans = 0
        if all(used):
            ans += 1
        for i, d in enumerate((3, 7, 5)):
            if 10 * n + d <= N:
                cur = used[i]
                used[i] = True
                ans += rec(10 * n + d, used)
                used[i] = cur
        return ans

    print((rec(0, [False, False, False])))
    return


if __name__ == "__main__":
    main()

-    def rec(vec): -        if vec and int("".join(vec)) > N: -            return 0 +    def rec(n, used): -        if all(c in vec for c in "357"): +        if all(used): -        for c in "357": -            vec.append(c) -            ans += rec(vec) -            vec.pop() +        for i, d in enumerate((3, 7, 5)): +            if 10 * n + d <= N: +                cur = used[i] +                used[i] = True +                ans += rec(10 * n + d, used) +                used[i] = cur -    ans = rec([]) -    print(ans) +    print((rec(0, [False, False, False])))