def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(i) > 0 for i in '357') else 0

    for i in '357':
        ret += dfs(s + i)
    return ret


n = int(input())

print(dfs('0'))