def resolve():

    from collections import deque

    n = int(eval(input()))

    ans = 0

    num = deque([3,5,7])

    while num[0] <= n:

        test = num.popleft()

        num.append(test * 10 + 3)

        num.append(test * 10 + 5)

        num.append(test * 10 + 7)

        if list(set([int(x) for x in list(str(test))])) == [3,5,7]:

            ans += 1

    print(ans)



resolve()
def resolve():

    from collections import deque



    def checker(n):

        n = str(n)

        OK3 = False

        OK5 = False

        OK7 = False

        for i in n:

            if i == "3":

                OK3 = True

            elif i== "5":

                OK5 = True

            elif i == "7":

                OK7 = True

        if OK3 and OK5 and OK7:

            return True

        else:

            return False



    n = int(eval(input()))

    if n < 357:

        print((0))

    else:

        ans = 0

        nxt = [3, 5, 7]

        nxt = deque(nxt)

        OK = True

        while OK:

            a = nxt.popleft()

            if a > n:

                break

            nxt.append(a*10+3)

            nxt.append(a * 10 + 5)

            nxt.append(a * 10 + 7)

            if checker(a):

                ans += 1

        print(ans)

resolve()
def resolve():
    from collections import deque

    n = int(eval(input()))
    ans = 0
    num = deque([3, 5, 7])
    while num[0] <= n:
        test = num.popleft()
        num.append(test * 10 + 3)
        num.append(test * 10 + 5)
        num.append(test * 10 + 7)
        if list(set([int(x) for x in list(str(test))])) == [3, 5, 7]:
            ans += 1
    print(ans)


resolve()

def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i == "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(eval(input()))
    if n < 357:
        print((0))
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a * 10 + 3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
        print(ans)


resolve()

+    def checker(n): +        n = str(n) +        OK3 = False +        OK5 = False +        OK7 = False +        for i in n: +            if i == "3": +                OK3 = True +            elif i == "5": +                OK5 = True +            elif i == "7": +                OK7 = True +        if OK3 and OK5 and OK7: +            return True +        else: +            return False + -    ans = 0 -    num = deque([3, 5, 7]) -    while num[0] <= n: -        test = num.popleft() -        num.append(test * 10 + 3) -        num.append(test * 10 + 5) -        num.append(test * 10 + 7) -        if list(set([int(x) for x in list(str(test))])) == [3, 5, 7]: -            ans += 1 -    print(ans) +    if n < 357: +        print((0)) +    else: +        ans = 0 +        nxt = [3, 5, 7] +        nxt = deque(nxt) +        OK = True +        while OK: +            a = nxt.popleft() +            if a > n: +                break +            nxt.append(a * 10 + 3) +            nxt.append(a * 10 + 5) +            nxt.append(a * 10 + 7) +            if checker(a): +                ans += 1 +        print(ans)