def main():

    global results, S

    S = int(eval(input()))

    S_str = str(S)

    results = []

    for i in range(3, len(S_str) + 1):

        bfs(i, '')

    print((len(results)))





def bfs(i, s):

    global results, S

    if i == 0:

        if int(s) <= S and len(set(s)) == 3:

            results.append(s)

        return

    i -= 1

    bfs(i, s + '3')

    bfs(i, s + '5')

    bfs(i, s + '7')





if __name__ == '__main__':

    main()

def main():

    global result, S

    S = int(eval(input()))

    result = 0

    bfs(0, '')

    print(result)





def bfs(i, s):

    global result, S

    if s != '' and int(s) <= S and len(set(s)) == 3:

        result += 1

    if i == len(str(S)):

        return

    i += 1

    bfs(i, s + '3')

    bfs(i, s + '5')

    bfs(i, s + '7')





if __name__ == '__main__':

    main()

def main():
    global results, S
    S = int(eval(input()))
    S_str = str(S)
    results = []
    for i in range(3, len(S_str) + 1):
        bfs(i, "")
    print((len(results)))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + "3")
    bfs(i, s + "5")
    bfs(i, s + "7")


if __name__ == "__main__":
    main()

def main():
    global result, S
    S = int(eval(input()))
    result = 0
    bfs(0, "")
    print(result)


def bfs(i, s):
    global result, S
    if s != "" and int(s) <= S and len(set(s)) == 3:
        result += 1
    if i == len(str(S)):
        return
    i += 1
    bfs(i, s + "3")
    bfs(i, s + "5")
    bfs(i, s + "7")


if __name__ == "__main__":
    main()

-    global results, S +    global result, S -    S_str = str(S) -    results = [] -    for i in range(3, len(S_str) + 1): -        bfs(i, "") -    print((len(results))) +    result = 0 +    bfs(0, "") +    print(result) -    global results, S -    if i == 0: -        if int(s) <= S and len(set(s)) == 3: -            results.append(s) +    global result, S +    if s != "" and int(s) <= S and len(set(s)) == 3: +        result += 1 +    if i == len(str(S)): -    i -= 1 +    i += 1