def nextn(n):

    if n == 0:

        return 3

    elif n % 10 == 3:

        return n+2

    elif n % 10== 5:

        return n+2

    elif n % 10 ==7:

        return nextn(n//10)*10 + 3



N = int(eval(input()))

n = 357

ans = 0

while n <= N:

    s = str(n)

    a = [False,False,False]

    for c in s:

        if c == '3':

            a[0] = True

        elif c == '5':

            a[1] = True

        elif c == '7':

            a[2] = True

        else:

            print(s)

    if all(a):

        ans += 1

    n = nextn(n) 

print(ans)

def nexti(i):

    if i == 0:

        return 3

    elif i % 10 == 3:

        return i + 2

    elif i % 10== 5:

        return i + 2

    elif i % 10 ==7:

        return nexti(i//10)*10 + 3



n = int(eval(input()))

nn = 0

i = 357



while i <= n:

  s = str(i)

  if '3' in s:

    if '5' in s:

      if '7' in s:

        #print(i)

        nn += 1

  if i % 10 == 7:

    i = nexti(i)

  else:

    i +=2

print(nn)
def nextn(n):
    if n == 0:
        return 3
    elif n % 10 == 3:
        return n + 2
    elif n % 10 == 5:
        return n + 2
    elif n % 10 == 7:
        return nextn(n // 10) * 10 + 3


N = int(eval(input()))
n = 357
ans = 0
while n <= N:
    s = str(n)
    a = [False, False, False]
    for c in s:
        if c == "3":
            a[0] = True
        elif c == "5":
            a[1] = True
        elif c == "7":
            a[2] = True
        else:
            print(s)
    if all(a):
        ans += 1
    n = nextn(n)
print(ans)

def nexti(i):
    if i == 0:
        return 3
    elif i % 10 == 3:
        return i + 2
    elif i % 10 == 5:
        return i + 2
    elif i % 10 == 7:
        return nexti(i // 10) * 10 + 3


n = int(eval(input()))
nn = 0
i = 357
while i <= n:
    s = str(i)
    if "3" in s:
        if "5" in s:
            if "7" in s:
                # print(i)
                nn += 1
    if i % 10 == 7:
        i = nexti(i)
    else:
        i += 2
print(nn)

-def nextn(n): -    if n == 0: +def nexti(i): +    if i == 0: -    elif n % 10 == 3: -        return n + 2 -    elif n % 10 == 5: -        return n + 2 -    elif n % 10 == 7: -        return nextn(n // 10) * 10 + 3 +    elif i % 10 == 3: +        return i + 2 +    elif i % 10 == 5: +        return i + 2 +    elif i % 10 == 7: +        return nexti(i // 10) * 10 + 3 -N = int(eval(input())) -n = 357 -ans = 0 -while n <= N: -    s = str(n) -    a = [False, False, False] -    for c in s: -        if c == "3": -            a[0] = True -        elif c == "5": -            a[1] = True -        elif c == "7": -            a[2] = True -        else: -            print(s) -    if all(a): -        ans += 1 -    n = nextn(n) -print(ans) +n = int(eval(input())) +nn = 0 +i = 357 +while i <= n: +    s = str(i) +    if "3" in s: +        if "5" in s: +            if "7" in s: +                # print(i) +                nn += 1 +    if i % 10 == 7: +        i = nexti(i) +    else: +        i += 2 +print(nn)