n = int(raw_input())

def count(sc):
    c3 = 0
    c5 = 0
    c7 = 0
    for c in sc:
        if c == "3":
            c3 += 1
        elif c == "5":
            c5 += 1
        elif c == "7":
            c7 += 1
        else:
            raise ValueError("error!")
    return c3 > 0 and c5 > 0 and c7 > 0
            

def up(tsc):
    res = ['0']*(len(tsc)+1)
    done = False
    i = len(tsc) - 1
    while not done and i >= -1:
        if tsc[i] == '7':
            carry = True
            res[i+1] = '3'
        elif tsc[i] == '5':
            res[i+1] = "7"
            done = True
        elif tsc[i] == '3':
            res[i+1] = "5"
            done = True
        elif i == -1:
            res[i+1] == '3'
            done = True
        i -= 1
    for i in range(i, -1, -1):
        res[i+1] = tsc[i]
    if res[0] == "0":
        return "".join(res[1:])
    else:
        return "".join(res)
        
def solve(n):
    tsc = "357"
    res = 0
    while int(tsc) <= n:
        if count(tsc):
            res += 1
        tsc = up(tsc)
    return res
print solve(n)
        
        
        
    
        