n=int(eval(input()))

c=0

l=[3,5,7]

L=[]

for i1 in l:

  for i2 in l:

    for i3 in l:

      for i4 in l:

        for i5 in l:

          L.append(10000*i1+1000*i2+100*i3+10*i4+i5)

for i in range(min(n+1,10000)):

  l=str(i)

  if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1

for j in L:

  for i in range(j,n+1,100000):

    l=str(i)

    if '3' in l and '5' in l and '7' in l and '0' not in l and '1' not in l and '2' not in l and '4' not in l and '6' not in l and '8' not in l and '9' not in l:c+=1

print(c)
n=int(eval(input()))

c=0

l=[0,3,5,7]

for i1 in l:

 for i2 in l:

  for i3 in l:

   for i4 in l:

    for i5 in l:

     for i6 in l:

      for i7 in l:

       for i8 in l:

        for i9 in l:

         x=str(i1+10*i2+100*i3+1000*i4+10000*i5+100000*i6+1000000*i7+10000000*i8+100000000*i9)

         if '3' in x and '5' in x and '7' in x and '0' not in x and int(x)<=n:c+=1

print(c)
n = int(eval(input()))
c = 0
l = [3, 5, 7]
L = []
for i1 in l:
    for i2 in l:
        for i3 in l:
            for i4 in l:
                for i5 in l:
                    L.append(10000 * i1 + 1000 * i2 + 100 * i3 + 10 * i4 + i5)
for i in range(min(n + 1, 10000)):
    l = str(i)
    if (
        "3" in l
        and "5" in l
        and "7" in l
        and "0" not in l
        and "1" not in l
        and "2" not in l
        and "4" not in l
        and "6" not in l
        and "8" not in l
        and "9" not in l
    ):
        c += 1
for j in L:
    for i in range(j, n + 1, 100000):
        l = str(i)
        if (
            "3" in l
            and "5" in l
            and "7" in l
            and "0" not in l
            and "1" not in l
            and "2" not in l
            and "4" not in l
            and "6" not in l
            and "8" not in l
            and "9" not in l
        ):
            c += 1
print(c)

n = int(eval(input()))
c = 0
l = [0, 3, 5, 7]
for i1 in l:
    for i2 in l:
        for i3 in l:
            for i4 in l:
                for i5 in l:
                    for i6 in l:
                        for i7 in l:
                            for i8 in l:
                                for i9 in l:
                                    x = str(
                                        i1
                                        + 10 * i2
                                        + 100 * i3
                                        + 1000 * i4
                                        + 10000 * i5
                                        + 100000 * i6
                                        + 1000000 * i7
                                        + 10000000 * i8
                                        + 100000000 * i9
                                    )
                                    if (
                                        "3" in x
                                        and "5" in x
                                        and "7" in x
                                        and "0" not in x
                                        and int(x) <= n
                                    ):
                                        c += 1
print(c)

-l = [3, 5, 7] -L = [] +l = [0, 3, 5, 7] -                    L.append(10000 * i1 + 1000 * i2 + 100 * i3 + 10 * i4 + i5) -for i in range(min(n + 1, 10000)): -    l = str(i) -    if ( -        "3" in l -        and "5" in l -        and "7" in l -        and "0" not in l -        and "1" not in l -        and "2" not in l -        and "4" not in l -        and "6" not in l -        and "8" not in l -        and "9" not in l -    ): -        c += 1 -for j in L: -    for i in range(j, n + 1, 100000): -        l = str(i) -        if ( -            "3" in l -            and "5" in l -            and "7" in l -            and "0" not in l -            and "1" not in l -            and "2" not in l -            and "4" not in l -            and "6" not in l -            and "8" not in l -            and "9" not in l -        ): -            c += 1 +                    for i6 in l: +                        for i7 in l: +                            for i8 in l: +                                for i9 in l: +                                    x = str( +                                        i1 +                                        + 10 * i2 +                                        + 100 * i3 +                                        + 1000 * i4 +                                        + 10000 * i5 +                                        + 100000 * i6 +                                        + 1000000 * i7 +                                        + 10000000 * i8 +                                        + 100000000 * i9 +                                    ) +                                    if ( +                                        "3" in x +                                        and "5" in x +                                        and "7" in x +                                        and "0" not in x +                                        and int(x) <= n +                                    ): +                                        c += 1