N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if '7' in s and '5' in s and '3' in s else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))