
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

g_comb_table ={}
def Comb(n, k):
    global g_comb_table
    if (n, k) in g_comb_table:
        return g_comb_table[(n, k)]
    if n == k or k == 0:
        g_comb_table[(n, k)] = 1
        return 1L
    elif k == 1:
        g_comb_table[(n, k)] = n
        return n
    g_comb_table[(n, k)] = Comb(n-1, k-1) + Comb(n-1, k)
    return g_comb_table[(n, k)]



def count(dig, msd, msd_bound):
    if msd < msd_bound:
        return int(3 ** max(0, (dig - 3))) * max(0, (dig - 1)) * max(0, (dig - 2)) * max(0, (dig - 3))
    else:
        return int(3 ** max(0, (dig - 3))) * max(0, (dig - 2)) * max(0,(dig - 1)) * max(0, (dig - 2))


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    S = "0753"
    already = set([])
    count = 0
    for s1 in S:
        for s2 in S:
            for s3 in S:
                for s4 in S:
                    for s5 in S:
                        for s6 in S:
                            for s7 in S:
                                for s8 in S:
                                    for s9 in S:
                                        s = s1+s2+s3+s4+s5+s6+s7+s8+s9
                                        s = s.strip()
                                        if (len(s) == 0): continue;
                                        i = int(s1+s2+s3+s4+s5+s6+s7+s8+s9)
                                        s = str(i)
                                        if i <= N and i not in already:
                                            if ("7" in s) and ("3" in s) and ("5" in s) and ("0" not in s):
                                                count += 1
                                                already.add(i)


##    dig = int(math.log(N, 10)) + (0 if N % 10 == 0 else 1)
##    msd = N / (10**(dig - 1))
##    if msd < 5:
##        las = 1
##    elif msd < 7:
##        las = 2
##    else:
##        las = 3
##    C1 = Comb(dig, 3)
##    top7 = count(dig, msd, 7)
##    top5 = count(dig, msd, 5)
##    top3 = count(dig, msd, 3)
    print  count

    #for i in range(dig):


if __name__ == '__main__':
    main()
