N = int(eval(input()))



def dfs(value, use):

    if int(value) > N:

        return 0



    res = int(use == 0b111)

    res += dfs(value + "7", use | 0b001)

    res += dfs(value + "5", use | 0b010)

    res += dfs(value + "3", use | 0b100)



    return res



print((dfs("0", 0)))



N = int(eval(input()))





def dfs(s):

    if int(s) > N:

        return 0



    res = 1 if all(s.count(c) > 0 for c in "357") else 0

    for c in "357":

        res += dfs(s + c)

    return res





print((dfs("0")))

N = int(eval(input()))


def dfs(value, use):
    if int(value) > N:
        return 0
    res = int(use == 0b111)
    res += dfs(value + "7", use | 0b001)
    res += dfs(value + "5", use | 0b010)
    res += dfs(value + "3", use | 0b100)
    return res


print((dfs("0", 0)))

N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    res = 1 if all(s.count(c) > 0 for c in "357") else 0
    for c in "357":
        res += dfs(s + c)
    return res


print((dfs("0")))

-def dfs(value, use): -    if int(value) > N: +def dfs(s): +    if int(s) > N: -    res = int(use == 0b111) -    res += dfs(value + "7", use | 0b001) -    res += dfs(value + "5", use | 0b010) -    res += dfs(value + "3", use | 0b100) +    res = 1 if all(s.count(c) > 0 for c in "357") else 0 +    for c in "357": +        res += dfs(s + c) -print((dfs("0", 0))) +print((dfs("0")))