import sys, re, os

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from fractions import gcd

def input(): return sys.stdin.readline().strip()

def STR(): return eval(input())

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def S_MAP(): return list(map(str, input().split()))

def LIST(): return list(map(int, input().split()))

def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)

inf = sys.maxsize

mod = 10 ** 9 + 7



def func(a, b):

    if a > b:

        return 0

    else:

        return 1



def solvedp(arr, ii):

    dp = [[0, 0] for _ in range(ii)]

    lenarr = len(arr)

    if ii == l:

        n0 = int(n[0])

        a = lenarr

        for j in range(lenarr):

            a -= func(n0, arr[j])

        dp[0][0] = a

        dp[0][1] = 1 if n0 in arr else 0

    else:

        dp[0][0] = lenarr

    for i in range(1, ii):

        if ii == l:

            ni = int(n[i])

            a = lenarr

            for j in range(lenarr):

                a -= func(ni, arr[j])

            dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a

            dp[i][1] = dp[i-1][1] if ni in arr else 0

        else:

            dp[i][0] = dp[i-1][0] * lenarr

    return dp



n = STR()

l = len(n)

ans = 0



arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]

for ii in range(1, l + 1):

    dp = [[[0, 0]for _ in range(ii)]for _ in range(7)]

    for i in range(7):

        dp[i] = solvedp(arr[i], ii)



    res = sum(dp[6][ii-1])

    for i in range(3, 6):

        res -= sum(dp[i][ii-1])

    for i in range(3):

        res += sum(dp[i][ii-1])

    ans += res

print(ans)

def STR(): return eval(input())



def func(a, b):

    if a > b:

        return 0

    else:

        return 1



def solve_dp(arr, ii):

    dp = [[0, 0] for _ in range(ii)]

    lenarr = len(arr)

    n0 = int(n[0])

    a = lenarr

    for j in range(lenarr):

        a -= func(n0, arr[j])

    dp[0][0] = a

    dp[0][1] = 1 if n0 in arr else 0

    for i in range(1, ii):

        ni = int(n[i])

        a = lenarr

        for j in range(lenarr):

            a -= func(ni, arr[j])

        dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a

        dp[i][1] = dp[i-1][1] if ni in arr else 0

    return sum(dp[ii-1])



n = STR()

l = len(n)

ans = 0



arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]

ans = solve_dp(arr[6], l)

for i in range(3):

    ans += solve_dp(arr[i], l)

for i in range(3, 6):

    ans -= solve_dp(arr[i], l)

for i in range(1, l):

    ans += pow(3, i) + 3 - 3 * pow(2, i)

print(ans)
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input():
    return sys.stdin.readline().strip()


def STR():
    return eval(input())


def INT():
    return int(eval(input()))


def MAP():
    return list(map(int, input().split()))


def S_MAP():
    return list(map(str, input().split()))


def LIST():
    return list(map(int, input().split()))


def S_LIST():
    return list(map(str, input().split()))


sys.setrecursionlimit(10**9)
inf = sys.maxsize
mod = 10**9 + 7


def func(a, b):
    if a > b:
        return 0
    else:
        return 1


def solvedp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    if ii == l:
        n0 = int(n[0])
        a = lenarr
        for j in range(lenarr):
            a -= func(n0, arr[j])
        dp[0][0] = a
        dp[0][1] = 1 if n0 in arr else 0
    else:
        dp[0][0] = lenarr
    for i in range(1, ii):
        if ii == l:
            ni = int(n[i])
            a = lenarr
            for j in range(lenarr):
                a -= func(ni, arr[j])
            dp[i][0] = dp[i - 1][0] * lenarr + dp[i - 1][1] * a
            dp[i][1] = dp[i - 1][1] if ni in arr else 0
        else:
            dp[i][0] = dp[i - 1][0] * lenarr
    return dp


n = STR()
l = len(n)
ans = 0
arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
for ii in range(1, l + 1):
    dp = [[[0, 0] for _ in range(ii)] for _ in range(7)]
    for i in range(7):
        dp[i] = solvedp(arr[i], ii)
    res = sum(dp[6][ii - 1])
    for i in range(3, 6):
        res -= sum(dp[i][ii - 1])
    for i in range(3):
        res += sum(dp[i][ii - 1])
    ans += res
print(ans)

def STR():
    return eval(input())


def func(a, b):
    if a > b:
        return 0
    else:
        return 1


def solve_dp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    n0 = int(n[0])
    a = lenarr
    for j in range(lenarr):
        a -= func(n0, arr[j])
    dp[0][0] = a
    dp[0][1] = 1 if n0 in arr else 0
    for i in range(1, ii):
        ni = int(n[i])
        a = lenarr
        for j in range(lenarr):
            a -= func(ni, arr[j])
        dp[i][0] = dp[i - 1][0] * lenarr + dp[i - 1][1] * a
        dp[i][1] = dp[i - 1][1] if ni in arr else 0
    return sum(dp[ii - 1])


n = STR()
l = len(n)
ans = 0
arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
ans = solve_dp(arr[6], l)
for i in range(3):
    ans += solve_dp(arr[i], l)
for i in range(3, 6):
    ans -= solve_dp(arr[i], l)
for i in range(1, l):
    ans += pow(3, i) + 3 - 3 * pow(2, i)
print(ans)

-import sys, re, os -from collections import deque, defaultdict, Counter -from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians -from itertools import permutations, combinations, product, accumulate -from operator import itemgetter, mul -from copy import deepcopy -from string import ascii_lowercase, ascii_uppercase, digits -from fractions import gcd - - -def input(): -    return sys.stdin.readline().strip() - - - - -def INT(): -    return int(eval(input())) - - -def MAP(): -    return list(map(int, input().split())) - - -def S_MAP(): -    return list(map(str, input().split())) - - -def LIST(): -    return list(map(int, input().split())) - - -def S_LIST(): -    return list(map(str, input().split())) - - -sys.setrecursionlimit(10**9) -inf = sys.maxsize -mod = 10**9 + 7 -def solvedp(arr, ii): +def solve_dp(arr, ii): -    if ii == l: -        n0 = int(n[0]) +    n0 = int(n[0]) +    a = lenarr +    for j in range(lenarr): +        a -= func(n0, arr[j]) +    dp[0][0] = a +    dp[0][1] = 1 if n0 in arr else 0 +    for i in range(1, ii): +        ni = int(n[i]) -            a -= func(n0, arr[j]) -        dp[0][0] = a -        dp[0][1] = 1 if n0 in arr else 0 -    else: -        dp[0][0] = lenarr -    for i in range(1, ii): -        if ii == l: -            ni = int(n[i]) -            a = lenarr -            for j in range(lenarr): -                a -= func(ni, arr[j]) -            dp[i][0] = dp[i - 1][0] * lenarr + dp[i - 1][1] * a -            dp[i][1] = dp[i - 1][1] if ni in arr else 0 -        else: -            dp[i][0] = dp[i - 1][0] * lenarr -    return dp +            a -= func(ni, arr[j]) +        dp[i][0] = dp[i - 1][0] * lenarr + dp[i - 1][1] * a +        dp[i][1] = dp[i - 1][1] if ni in arr else 0 +    return sum(dp[ii - 1]) -for ii in range(1, l + 1): -    dp = [[[0, 0] for _ in range(ii)] for _ in range(7)] -    for i in range(7): -        dp[i] = solvedp(arr[i], ii) -    res = sum(dp[6][ii - 1]) -    for i in range(3, 6): -        res -= sum(dp[i][ii - 1]) -    for i in range(3): -        res += sum(dp[i][ii - 1]) -    ans += res +ans = solve_dp(arr[6], l) +for i in range(3): +    ans += solve_dp(arr[i], l) +for i in range(3, 6): +    ans -= solve_dp(arr[i], l) +for i in range(1, l): +    ans += pow(3, i) + 3 - 3 * pow(2, i)