# 2019/06/08
# AtCoder Beginner Contest 114 - C

def makeval(in_sn):
    div = int(in_sn / 4)
    rem = in_sn % 4
    if div == 0:
        if rem == 0:
            return "X"
        elif rem == 1:
            return "3"
        elif rem == 2:
            return "5"
        elif rem == 3:
            return "7"
    else:
        ret = makeval(div)
        if rem == 0:
            return ret + "3"
        elif rem == 1:
            return ret + "5"
        elif rem == 2:
            return ret + "7"
        elif rem == 3:
            return "X"
# Input
n = int(input())

wval = 1
cnt = 0
idx = 1

while(wval <= n):
    wstr = makeval(idx)
    if ("X" in wstr) == False:
        if ("3" in wstr) == True and ("5" in wstr) == True and ("7" in wstr) == True :
            wval = int(wstr)
            cnt += 1
    
    idx += 1

cnt -= 1

# Output
print(cnt)
