N=int(eval(input()))

f=lambda c:sum([list([z+y for z in f(c-1)]) for y in '357'],[]) if c!=0 else ['']

print((sum([len(list([y for y in list([len(set(sorted(x))) for x in [z for z in f(e+1) if int(z)<=N]]) if y==3])) for e in range(10)])))

N=int(eval(input()))

r=filter

f=lambda c:sum([[z+y for z in f(c-1)]for y in'357'],[]) if c!=0 else ['']

print((sum([len(r(lambda y:y==3,[len(set(sorted(x))) for x in r(lambda z:int(z)<=N,f(e+1))]))for e in range(10)])))

N = int(eval(input()))
f = (
    lambda c: sum([list([z + y for z in f(c - 1)]) for y in "357"], [])
    if c != 0
    else [""]
)
print(
    (
        sum(
            [
                len(
                    list(
                        [
                            y
                            for y in list(
                                [
                                    len(set(sorted(x)))
                                    for x in [z for z in f(e + 1) if int(z) <= N]
                                ]
                            )
                            if y == 3
                        ]
                    )
                )
                for e in range(10)
            ]
        )
    )
)

N = int(eval(input()))
r = filter
f = lambda c: sum([[z + y for z in f(c - 1)] for y in "357"], []) if c != 0 else [""]
print(
    (
        sum(
            [
                len(
                    r(
                        lambda y: y == 3,
                        [
                            len(set(sorted(x)))
                            for x in r(lambda z: int(z) <= N, f(e + 1))
                        ],
                    )
                )
                for e in range(10)
            ]
        )
    )
)

-f = ( -    lambda c: sum([list([z + y for z in f(c - 1)]) for y in "357"], []) -    if c != 0 -    else [""] -) +r = filter +f = lambda c: sum([[z + y for z in f(c - 1)] for y in "357"], []) if c != 0 else [""] -                    list( +                    r( +                        lambda y: y == 3, -                            y -                            for y in list( -                                [ -                                    len(set(sorted(x))) -                                    for x in [z for z in f(e + 1) if int(z) <= N] -                                ] -                            ) -                            if y == 3 -                        ] +                            len(set(sorted(x))) +                            for x in r(lambda z: int(z) <= N, f(e + 1)) +                        ],