n = int(input())

def count_753(s):
    if int(s) > n:
        return 0
    ret = all((c in s for c in '753'))
    for c in '753':
        ret += count_753(s + c)
    return ret

print(count_753('0'))