import itertools

def seven_five_five(n):
    s = list(str(n))
    len_s = len(s)
    semi_753 = []
    for j in range(3,len_s+1):
        for i in itertools.product(['3','5','7'],repeat=j):
            l = ''.join(i)
            #print l
            semi_753.append(l)

    target = [i for i in semi_753 if int(i) > 356 and int(i) <= n]
    #print target
    count = 0
    for i in target:
        v = str(i)
        flag = [False,False,False]
        for j in list(v):
            if j == '7':
                flag[0] = True
            elif j == '5':
                flag[1] = True
            elif j == '3':
                flag[2] = True
            else:
                break

            if flag[0] and flag[1] and flag[2]:
                #print i
                count += 1
                break
    print count
if __name__ == '__main__':
    n =  int(raw_input())
    seven_five_five(n)