N = eval(input())

D = len(N)

N = int(N)

ans = 0

def dfs(v):

    global ans

    if v > N: return 0

    if len(set(str(v))) == 3: ans += 1

    for i in (3,5,7):

        dfs(v*10+i)



dfs(0)

print(ans)

N = int(eval(input()))

ans = 0

def dfs(v):

    global ans

    if v > N: return 0

    if len(set(str(v))) == 3: ans += 1

    for i in (3,5,7):

        dfs(v*10+i)

dfs(0)

print(ans)

N = eval(input())
D = len(N)
N = int(N)
ans = 0


def dfs(v):
    global ans
    if v > N:
        return 0
    if len(set(str(v))) == 3:
        ans += 1
    for i in (3, 5, 7):
        dfs(v * 10 + i)


dfs(0)
print(ans)

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


def dfs(v):
    global ans
    if v > N:
        return 0
    if len(set(str(v))) == 3:
        ans += 1
    for i in (3, 5, 7):
        dfs(v * 10 + i)


dfs(0)
print(ans)

-N = eval(input()) -D = len(N) -N = int(N) +N = int(eval(input()))