#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list

#from itertools import combinations # (string,3) 3回



mod = 10**9 + 7



def readInts():

  return list(map(int,input().split()))

def main():

    from collections import deque

    d = deque()

    lc = [3,5,7]

    cnt = 0

    #nya = 0

    d.append(0)

    LIST = []

    n = int(eval(input()))

    flag = False

    while True:



        a = d.popleft()

        #print(a)

        if a > n:

            #print(a,nya)

            print(cnt)

            exit()        #print(n,a)

        if len(str(a)) == 3 and (not flag):



            flag = True

        if flag and (str(a).count('3') >= 1 and str(a).count('5') >= 1 and str(a).count('7') >= 1):

            cnt += 1

        for i in range(3):

            nya = a * 10 + lc[i]

            d.append(nya)

if __name__ == '__main__':

  main()

#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list

#from itertools import combinations # (string,3) 3回

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#



mod = 10**9 + 7



def readInts():

  return list(map(int,input().split()))

def main():

    n = int(eval(input()))

    nl = len(str(n))



    from collections import deque

    que = deque()



    selec = [3,5,7]

    que.append(0)

    ans = 0

    swi = False

    while que:

        a = que.popleft()

        sa = str(a)

        #print(a,sa,n)

        for i in range(3):

            que.append(a*10 + selec[i])

        if a > n:

            break

        elif (not swi) and sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:

            swi = True

            ans += 1

        elif sa.count('5') >= 1 and sa.count('7') >= 1 and sa.count('3') >= 1:

            ans += 1

    print(ans)



if __name__ == '__main__':

  main()

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list
# from itertools import combinations # (string,3) 3回
mod = 10**9 + 7


def readInts():
    return list(map(int, input().split()))


def main():
    from collections import deque

    d = deque()
    lc = [3, 5, 7]
    cnt = 0
    # nya = 0
    d.append(0)
    LIST = []
    n = int(eval(input()))
    flag = False
    while True:
        a = d.popleft()
        # print(a)
        if a > n:
            # print(a,nya)
            print(cnt)
            exit()  # print(n,a)
        if len(str(a)) == 3 and (not flag):
            flag = True
        if flag and (
            str(a).count("3") >= 1 and str(a).count("5") >= 1 and str(a).count("7") >= 1
        ):
            cnt += 1
        for i in range(3):
            nya = a * 10 + lc[i]
            d.append(nya)


if __name__ == "__main__":
    main()

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list
# from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
mod = 10**9 + 7


def readInts():
    return list(map(int, input().split()))


def main():
    n = int(eval(input()))
    nl = len(str(n))
    from collections import deque

    que = deque()
    selec = [3, 5, 7]
    que.append(0)
    ans = 0
    swi = False
    while que:
        a = que.popleft()
        sa = str(a)
        # print(a,sa,n)
        for i in range(3):
            que.append(a * 10 + selec[i])
        if a > n:
            break
        elif (
            (not swi)
            and sa.count("5") >= 1
            and sa.count("7") >= 1
            and sa.count("3") >= 1
        ):
            swi = True
            ans += 1
        elif sa.count("5") >= 1 and sa.count("7") >= 1 and sa.count("3") >= 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

+# +# +# pythonで無理なときは、pypyでやると正解するかも！！ +# +# +    n = int(eval(input())) +    nl = len(str(n)) -    d = deque() -    lc = [3, 5, 7] -    cnt = 0 -    # nya = 0 -    d.append(0) -    LIST = [] -    n = int(eval(input())) -    flag = False -    while True: -        a = d.popleft() -        # print(a) +    que = deque() +    selec = [3, 5, 7] +    que.append(0) +    ans = 0 +    swi = False +    while que: +        a = que.popleft() +        sa = str(a) +        # print(a,sa,n) +        for i in range(3): +            que.append(a * 10 + selec[i]) -            # print(a,nya) -            print(cnt) -            exit()  # print(n,a) -        if len(str(a)) == 3 and (not flag): -            flag = True -        if flag and ( -            str(a).count("3") >= 1 and str(a).count("5") >= 1 and str(a).count("7") >= 1 +            break +        elif ( +            (not swi) +            and sa.count("5") >= 1 +            and sa.count("7") >= 1 +            and sa.count("3") >= 1 -            cnt += 1 -        for i in range(3): -            nya = a * 10 + lc[i] -            d.append(nya) +            swi = True +            ans += 1 +        elif sa.count("5") >= 1 and sa.count("7") >= 1 and sa.count("3") >= 1: +            ans += 1 +    print(ans)