N=int(input())

def dfs(cur,use,counter):
    if cur>N:
        return 0
    
    elif use==0b111:
        counter=1

    counter+=dfs(cur*10+7,use | 0b001, counter)
    counter+=dfs(cur*10+5,use | 0b010, counter)
    counter+=dfs(cur*10+3,use | 0b100, counter)

    return counter

print(dfs(0,0,0))
