
def dfs(s, t):
    if int(s) > t:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c, t)
    return ret

n = int(input())
print(dfs('0', n))