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, min(N_len, 9)+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(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(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, min(N_len, 9) + 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(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()

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