N = int(eval(input()))



def search(s) :

    if int(s) > N :

        return 0

    ret = 1 if all(s.count(i) > 0 for i in ['7', '5', '3']) else 0  # 753数

    for c in ['7', '5', '3'] :

        ret += search(s + c)

    return ret



ans = search('0')



print(ans)
N = int(eval(input()))



def dp(now) :

    if int(now) > N :

        return 0

    count = 0

    if all(x in now for x in ['7', '5', '3']) :

        count += 1

    for x in ['7', '5', '3'] :

        count += dp(now + x)

    return count



ans = dp('0')

print(ans)
N = int(eval(input()))


def search(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(i) > 0 for i in ["7", "5", "3"]) else 0  # 753数
    for c in ["7", "5", "3"]:
        ret += search(s + c)
    return ret


ans = search("0")
print(ans)

N = int(eval(input()))


def dp(now):
    if int(now) > N:
        return 0
    count = 0
    if all(x in now for x in ["7", "5", "3"]):
        count += 1
    for x in ["7", "5", "3"]:
        count += dp(now + x)
    return count


ans = dp("0")
print(ans)

-def search(s): -    if int(s) > N: +def dp(now): +    if int(now) > N: -    ret = 1 if all(s.count(i) > 0 for i in ["7", "5", "3"]) else 0  # 753数 -    for c in ["7", "5", "3"]: -        ret += search(s + c) -    return ret +    count = 0 +    if all(x in now for x in ["7", "5", "3"]): +        count += 1 +    for x in ["7", "5", "3"]: +        count += dp(now + x) +    return count -ans = search("0") +ans = dp("0")