N = int(eval(input()))



def dfs(x):

    if x > N:

        return 0



    san, go, nana = 0, 0, 0

    c = x

    for i in range(len(str(c))):

        if c % 10 == 3:

            san += 1

        elif c % 10 == 5:

            go += 1

        elif c % 10 == 7:

            nana += 1

        c = c // 10

    if san > 0 and go > 0 and nana > 0:

        ret = 1

    else:

        ret = 0



    for i in [3, 5, 7]:

        ret += dfs(10*x + i)



    return ret



print((dfs(0)))

N = int(eval(input()))



cnt = 0

nums = ''



def dfs(nums):

    global cnt

    

    if len(nums) >= 10:

        return

        

    k = list(nums)

    k = set(nums)



    if len(nums) >= 1:

        if int(nums) <= N and len(k) >= 3:

            cnt += 1

    

    dfs(nums + '3')

    dfs(nums + '5')

    dfs(nums + '7')



    return



dfs(nums)



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


def dfs(x):
    if x > N:
        return 0
    san, go, nana = 0, 0, 0
    c = x
    for i in range(len(str(c))):
        if c % 10 == 3:
            san += 1
        elif c % 10 == 5:
            go += 1
        elif c % 10 == 7:
            nana += 1
        c = c // 10
    if san > 0 and go > 0 and nana > 0:
        ret = 1
    else:
        ret = 0
    for i in [3, 5, 7]:
        ret += dfs(10 * x + i)
    return ret


print((dfs(0)))

N = int(eval(input()))
cnt = 0
nums = ""


def dfs(nums):
    global cnt
    if len(nums) >= 10:
        return
    k = list(nums)
    k = set(nums)
    if len(nums) >= 1:
        if int(nums) <= N and len(k) >= 3:
            cnt += 1
    dfs(nums + "3")
    dfs(nums + "5")
    dfs(nums + "7")
    return


dfs(nums)
print(cnt)

+cnt = 0 +nums = "" -def dfs(x): -    if x > N: -        return 0 -    san, go, nana = 0, 0, 0 -    c = x -    for i in range(len(str(c))): -        if c % 10 == 3: -            san += 1 -        elif c % 10 == 5: -            go += 1 -        elif c % 10 == 7: -            nana += 1 -        c = c // 10 -    if san > 0 and go > 0 and nana > 0: -        ret = 1 -    else: -        ret = 0 -    for i in [3, 5, 7]: -        ret += dfs(10 * x + i) -    return ret +def dfs(nums): +    global cnt +    if len(nums) >= 10: +        return +    k = list(nums) +    k = set(nums) +    if len(nums) >= 1: +        if int(nums) <= N and len(k) >= 3: +            cnt += 1 +    dfs(nums + "3") +    dfs(nums + "5") +    dfs(nums + "7") +    return -print((dfs(0))) +dfs(nums) +print(cnt)