def main():

    N = int(eval(input()))



    def recur(s):

        if int(s) > N:

            return 0

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

        for c in '753':

            ret += recur(s + c)

        return ret

    print((recur('0')))





if __name__ == '__main__':

    main()

def main():

    N = int(input())

    N_len = len(str(N))

    if N_len < 3:

        return print(0)

    from itertools import product

    ans_set = set()

    for k in range(3, N_len+1):

        ans_set = ans_set.union({s for s in product("753", repeat=k)

                                 if int("".join(s)) <= N and

                                 len(set(s) & set("753")) == 3})

    print(len(ans_set))





if __name__ == '__main__':

    main()

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

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

    print((recur("0")))


if __name__ == "__main__":
    main()

def main():
    N = int(input())
    N_len = len(str(N))
    if N_len < 3:
        return print(0)
    from itertools import product

    ans_set = set()
    for k in range(3, N_len + 1):
        ans_set = ans_set.union(
            {
                s
                for s in product("753", repeat=k)
                if int("".join(s)) <= N and len(set(s) & set("753")) == 3
            }
        )
    print(len(ans_set))


if __name__ == "__main__":
    main()

-    N = int(eval(input())) +    N = int(input()) +    N_len = len(str(N)) +    if N_len < 3: +        return print(0) +    from itertools import product -    def recur(s): -        if int(s) > N: -            return 0 -        ret = 1 if all(s.count(c) for c in "753") else 0 -        for c in "753": -            ret += recur(s + c) -        return ret - -    print((recur("0"))) +    ans_set = set() +    for k in range(3, N_len + 1): +        ans_set = ans_set.union( +            { +                s +                for s in product("753", repeat=k) +                if int("".join(s)) <= N and len(set(s) & set("753")) == 3 +            } +        ) +    print(len(ans_set))