def C3():
    N = int(input())
    def make_list(s):
        S = [s]
        if int(s) <= N:
            S.extend(make_list(s + "3"))
            S.extend(make_list(s + "5"))
            S.extend(make_list(s + "7"))
        return S

    datalist = make_list("0")

    ans = 0
    for i in datalist:
        s = 0
        f = 0
        t = 0
        for j in list(i):
            print(j)
            if j == "7":
                s = 1
            if j == "5":
                f = 1
            if j == "3":
                t = 1
        if s + f + t == 3 and int(i) <= N:
            ans += 1
    print(ans)
C3()