Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper.

Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$.


-----Input-----

The only input line contains the integer $n$ ($1 \le n \le 2\cdot10^9$).


-----Output-----

Print the maximum product of digits among all integers from $1$ to $n$.


-----Examples-----
Input
390

Output
216

Input
7

Output
7

Input
1000000000

Output
387420489



-----Note-----

In the first example the maximum product is achieved for $389$ (the product of digits is $3\cdot8\cdot9=216$).

In the second example the maximum product is achieved for $7$ (the product of digits is $7$).

In the third example the maximum product is achieved for $999999999$ (the product of digits is $9^9=387420489$).

Difficulty: EASY

Solutions:
def pr(n):
	pr = 1
	while n != 0:
		pr *= n % 10
		n //= 10
	return pr
n = int(input())
if n < 10:
	print(n)
	exit()
mx = pr(n)
past = 1
while n != 0:
	while n % 10 != 9 and len(str(n)) != 1:
		n -= 1
	mx = max(mx, pr(n) * past)
	past *= n % 10
	n //= 10
print(mx)


def pod(n):
	sum = 1
	while n > 0:
		sum *= n % 10
		n //= 10
	return sum
n = int(input())
ans = pod(n)
mod = 10
while n > 0:
	n -= n % mod + 1
	ans = max(ans, pod(n))
	mod *= 10
print(ans)


r = p = 1
for d in map(int, input()[::-1]):
	r = max(d * r, d * p - p)
	p *= 9
print(max(r, p // 9))


from functools import reduce

def solve(n):
	strn = str(n)
	ans = reduce(lambda a, b: a * b, [int(char) for char in strn])
	for i in range(len(strn)):
		if strn[i] == '0':
			continue
		listn = [int(char) for char in strn]
		listn[i] = listn[i] - 1
		for j in range(i + 1, len(strn)):
			listn[j] = 9
		start_i = 0
		if listn[i] == 0 and i == 0:
			start_i = 1
		if start_i >= len(listn):
			continue
		prod = reduce(lambda a, b: a * b, listn[start_i:])
		ans = max(prod, ans)
	return ans
n = int(input())
print(solve(n))


b = input()
j = len(b)
c = list(b)
j -= 1
d = 1
while j >= 1:
	d = d * 9
	j -= 1
e = int(b[0]) - 1
if e != 0:
	d = d * e
f = 1
j = len(b) - 1
B = ''
while j >= 1:
	e = int(c[j])
	g = int(c[j - 1])
	h = e * g
	i = (g - 1) * 9
	if i > h:
		l = len(B) - 1
		B = ''
		while l >= 0:
			B = B + '9'
			l -= 1
		B = '9' + B
		g -= 1
		c[j - 1] = str(g)
	else:
		B = c[j] + B
	j -= 1
B = c[0] + B
j = len(B) - 1
while j >= 0:
	f = f * int(B[j])
	j -= 1
f = max(f, d)
print(f)


def hasil(n):
	if n == 0:
		return 1
	if n < 10:
		return n
	else:
		return max(n % 10 * hasil(n // 10), 9 * hasil(n // 10 - 1))
str_angka = input()
print(hasil(int(str_angka)))


def getMax(num):
	arr = list(num)
	prod = 1
	for a in arr:
		prod = prod * int(a)
	return prod
n = input()
num = list(n)
i = len(n) - 1
maxP = getMax(n)
if len(n) > 1:
	while i > 0:
		num[i] = '9'
		while int(num[i - 1]) == 0:
			num[i - 1] = '9'
			i = i - 1
		if int(num[i - 1]) > 1:
			num[i - 1] = str(int(num[i - 1]) - 1)
		maxP = max(getMax(''.join(num)), maxP)
		i = i - 1
	print(maxP)
else:
	print(n)


m = int(input())
i = 0

def getProduct(n):
	product = 1
	for item in n:
		product *= int(item)
	return product

def removeZero(n):
	global i
	while n[i] == 0:
		n[i] = 9
		i -= 1
	return n
storemax = 0
n = list(map(int, list(str(m))))
storemax = getProduct(n)
i = len(n) - 1
while i > 0:
	if n[i] == 0:
		n = removeZero(n)
		n[i] -= 1
	else:
		n[i] = 9
		if n[i - 1] != 0:
			n[i - 1] -= 1
		i -= 1
	if n[0] == 0:
		n.remove(0)
	temp = getProduct(n)
	if temp > storemax:
		storemax = temp
print(storemax)


n = int(input())
ans = []
a = 1
for i in str(n):
	a *= int(i)
ans.append(a)
for i in range(0, len(str(n))):
	k = n
	k -= 10 ** i
	if k < 0:
		continue
	mul = 9 ** i
	k = str(k)
	for j in range(0, len(str(k)) - i):
		mul *= int(list(k)[j])
	ans.append(mul)
if len(str(n)) == 1:
	print(n)
else:
	print(max(ans))


def solve(n):
	if n == 0:
		return 1
	elif n < 10:
		return n
	else:
		return max(n % 10 * solve(int(n / 10)), 9 * solve(int(n / 10) - 1))
n = int(input())
print(solve(n))


from functools import reduce
no = list(map(int, list(input())))
ans = reduce(lambda x, y: x * y, no)
ans = max(ans, pow(9, len(no) - 1))
i = len(no) - 1
while i != -1:
	no[i] = 9
	while i > 0 and no[i - 1] == 0:
		no[i - 1] = 9
		i -= 1
	if i == 0:
		break
	no[i - 1] -= 1
	ans = max(ans, reduce(lambda x, y: x * y, no))
print(ans)


n = input()

def f(number):
	if number[0] == '0':
		return -1
	if len(number) == 1:
		return int(number[0])
	c = int(number[0]) - 1
	if c == 0:
		c = 1
	return max(int(number[0]) * f(number[1:]), c * 9 ** (len(number) - 1))
print(f(n))


n = int(input())
n = list(map(int, list(str(n))))
nn = n[:]
for i in range(len(n) - 1, 0, -1):
	if n[i] == 9:
		continue
	elif n[i] == 0:
		n[i] = 9
		n[i - 1] -= 1
		for j in range(i - 1, 0, -1):
			if n[j] < 0:
				n[j] = 9
				n[j - 1] -= 1
			else:
				break
	elif n[i] * n[i - 1] < 9 * (n[i - 1] - 1):
		n[i - 1] -= 1
		for j in range(i, -1, -1):
			if n[j] < 0:
				n[j] = 9
				n[j - 1] -= 1
		n[i] = 9
mul = 1
for i in n:
	if i != 0:
		mul *= i
n = [9 for i in range(len(nn))]
n[0] = nn[0] - 1
for i in range(1, len(nn)):
	mul1 = 1
	for j in n:
		if j != 0:
			mul1 *= j
	if mul1 > mul:
		mul = mul1
	n[i - 1] += 1
	n[i] = nn[i] - 1
print(mul)


import collections
n = input()
i = len(n) - 1
k = 1
for t in n:
	k = k * int(t)
ans = k
while i:
	if n[i] == '0':
		n = str(int(n[:i + 1]) - 1) + n[i + 1:]
	elif n[i] != '9':
		n = str(int(n[:i + 1]) - int(n[i]) - 1) + n[i + 1:]
	i -= 1
	k = 1
	for t in n:
		k = k * int(t)
	ans = max(ans, k)
print(ans)


n = int(input())
L = list(map(int, str(n)))
LEN = len(L)
ANS = 1
for p in L:
	ANS *= p
if L[0] == 1:
	ANS = max(ANS, pow(9, LEN - 1))
for i in range(LEN - 1):
	CAND = 1
	for j in range(i):
		CAND *= L[j]
	CAND *= L[i] - 1
	for k in range(i + 1, LEN):
		CAND *= 9
	if ANS < CAND:
		ANS = CAND
print(ANS)


def digitsproduct(n):
	n = str(n)
	p = 1
	for i in range(len(n)):
		p = p * int(n[i])
	return p
n = int(input())
strn = str(n)
ans = digitsproduct(n)
for i in range(len(strn)):
	if strn[i] == '0':
		break
	newn = strn[:i] + str(int(strn[i]) - 1)
	for _ in range(i + 1, len(strn)):
		newn = newn + '9'
	newp = digitsproduct(int(newn))
	if newp > ans:
		ans = newp
print(ans)


def f(n):
	if n < 10:
		return max(1, n)
	return max(f(n // 10) * (n % 10), f(n // 10 - 1) * 9)
n = int(input())
print(f(n))


n = input()

def recur_max(num):
	if len(num) == 1:
		return int(num)
	elif num.startswith('1'):
		return 9 ** (len(num) - 1)
	elif num.startswith('0'):
		return 0
	else:
		return max(int(num[0]) * recur_max(num[1:]), (int(num[0]) - 1) * 9 ** (len(num) - 1))
print(recur_max(n))


def z(a):
	if a == 0:
		return 1
	elif a <= 9:
		return a
	else:
		return max(a % 10 * z(a // 10), 9 * z(a // 10 - 1))
print(z(int(input())))


import math
n = input()
maxxx = 1
for i in n:
	maxxx *= int(i)
razr = len(n) - 1
n = int(n)
while razr:
	cur = str(n // 10 ** razr - 1)
	if cur == '0':
		cur = ''
	cur += '9' * razr
	cur_rez = 1
	for i in cur:
		cur_rez *= int(i)
	if cur_rez > maxxx:
		maxxx = cur_rez
	razr -= 1
print(maxxx)


import functools

def mult(a, b):
	return int(a) * int(b)
inp = list(str(int(input())))
largest = int(functools.reduce(mult, inp))
prod = 1
while True:
	temp = prod * max(1, int(inp[0]) - 1) * 9 ** (len(inp) - 1)
	if temp > largest:
		largest = temp
	prod *= int(inp[0])
	inp.pop(0)
	if len(inp) == 0 or inp[0] == 0:
		break
print(largest)


def maxProd(N):
	if N == 0:
		return 1
	if N < 10:
		return N
	return max(maxProd(N // 10) * (N % 10), maxProd(N // 10 - 1) * 9)
N = int(input())
print(maxProd(N))


import sys

def calc(n):
	if n == 0:
		return 1
	if n < 10:
		return n
	x = max(int(n % 10) * int(calc(n / 10)), 9 * calc(int(n / 10) - 1))
	return x
n = int(input())
print(calc(n))


def pd(d):
	d = str(d)
	ans = 1
	for c in d:
		ans *= int(c)
	return ans
S = input()
D = int(S)
ans = pd(D)
if str(D)[0] == '1':
	ans = 9 ** (len(str(D)) - 1)
else:
	cur = 0
	while 10 ** cur < D:
		ans = max(ans, pd(D - D % 10 ** cur - 1))
		cur += 1
print(ans)


number = input().strip()
k = len(number)
prod_n = 1
for item in number:
	prod_n *= int(item)
maxs = [prod_n]
nums = [int(number)]
for i in range(0, k):
	nums.append('')
	prod = 1
	for j in range(i):
		prod *= int(number[j])
		nums[-1] += number[j]
	if not (i == 0 and number[i] == '1'):
		prod *= int(number[i]) - 1
	nums[-1] += str(int(number[i]) - 1)
	for j in range(i + 1, k):
		prod *= 9
		nums[-1] += '9'
	maxs.append(prod)
print(max(maxs))


def pro(b):
	k = 1
	for z in b:
		k *= z
	return k
n = s = int(input())
a = [int(i) for i in str(s)]
t = [9 for i in range(len(a) - 1)]
o = max(pro(t), pro(a))
for i in range(len(a) - 2, -1, -1):
	if a[i] != 0:
		c = [a[i] for i in range(i)]
		c.append(a[i] - 1)
		while len(c) != len(a):
			c.append(9)
		o = max([o, pro(c)])
print(o)


def solve(x):
	if x < 10:
		return x
	t = 1
	y = -1
	while t <= x:
		t *= 10
		y += 1
	t = t // 10
	if x == t:
		return 9 ** y
	a = x // t
	b = x % t
	c = a * solve(b)
	d = max(a - 1, 1) * 9 ** y
	return max(c, d)
n = int(input())
r = solve(n)
print(r)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L

def rec(kk, s):
	if kk == len(s):
		return 1
	k = int(s[kk])
	if k == 0:
		return 0
	if k != 1:
		return max((k - 1) * 9 ** (len(s) - kk - 1), k * rec(kk + 1, s))
	else:
		return rec(kk + 1, s)
c = cinn()
n = c.cin(str)
if n[0] == '1':
	print(9 ** (len(n) - 1))
else:
	print(rec(0, n))


import sys

def prod(L):
	ans = 1
	m = len(L)
	for i in range(0, m):
		ans = ans * L[i]
	return ans
n = int(sys.stdin.readline().strip())
x = str(n)
l = len(x)
A = [0] * l
for i in range(0, l):
	A[i] = int(x[i])
p = max([prod(A), 9 ** (l - 1)])
for i in range(1, l):
	A[l - i] = 9
	A[l - i - 1] = A[l - i - 1] - 1
	p = max([p, prod(A)])
print(p)


n = input()
mx = 9 ** int(len(n) - 1)
if len(n) == 1:
	print(n)
	exit()
cnt = 1
for i in n:
	cnt *= int(i)
if cnt > mx:
	mx = cnt
for i in range(len(n)):
	cur = n
	if cur[i] != '0':
		cur = cur[:i] + str(int(cur[i]) - 1) + '9' * (len(n) - i - 1)
	cnt = 1
	for j in cur:
		cnt *= int(j)
	if cnt > mx:
		mx = cnt
print(mx)


def pro(n):
	s = str(n)
	p = 1
	for i in s:
		p *= int(i)
	return p
s = input()
n = int(s)
l = len(s)
m = n
mp = pro(n)
for i in range(1, l):
	m = n - int(s[l - i:]) - 1
	p = pro(m)
	mp = max(mp, p)
print(mp)


from sys import stdin, stdout
from collections import defaultdict, Counter, deque
from bisect import bisect, bisect_left
import math
from itertools import permutations
import queue

def sumOfDigits(x):
	prod = 1
	while x:
		prod *= x % 10
		x //= 10
	return prod

def findMax(x):
	b = 1
	ans = x
	while x != 0:
		cur = (x - 1) * b + (b - 1)
		if sumOfDigits(cur) > sumOfDigits(ans) or (sumOfDigits(cur) == sumOfDigits(ans) and cur > ans):
			ans = cur
		x = x // 10
		b = b * 10
	return ans
I = stdin.readline
n = int(I())
ans = findMax(n)
prod = 1
for i in str(ans):
	prod *= int(i)
print(prod)


def digits(x):
	data = []
	while x != 0:
		data.append(x % 10)
		x = x // 10
	data.reverse()
	return data

def digits_reverse(data):
	x = 0
	for i in range(len(data)):
		x += 10 ** (len(data) - i - 1) * data[i]
	return x

def product_digit(x):
	data = digits(x)
	ans = 1
	for i in range(len(data)):
		ans = ans * data[i]
	return ans
N = int(input())
data = digits(N)
ans = [0] * (len(data) + 1)
for i in range(len(data)):
	x = 0
	for j in range(i + 1):
		x += 10 ** (len(data) - j - 1) * data[j]
	ans[i] = product_digit(x - 1)
ans[len(data)] = product_digit(N)
print(max(ans))


n = input()

def prod(s):
	ans = 1
	for c in s:
		ans = ans * int(c)
	return ans
ans = prod(n)
for i in range(len(n)):
	if n[i] != '0':
		if i == 0 and n[0] == '1':
			ans = max(ans, prod('9' * (len(n) - 1 - i)))
		else:
			ans = max(ans, prod(n[:i] + str(int(n[i]) - 1) + '9' * (len(n) - 1 - i)))
print(ans)


a = list(map(int, list(input())))
n = len(a)
p = n - 1
ans = []
k = 0
while p != -1:
	pro = 1
	ini = 0
	for i in range(n):
		if a[i] == 0 and ini == 0:
			continue
		else:
			ini = 1
			pro *= a[i]
	ans.append(pro)
	mila = -5
	for i in range(p, -1, -1):
		if a[i] != 0:
			mila = i
			break
	if mila != -5:
		for i in range(mila + 1, n, 1):
			a[i] = 9
		a[mila] = a[mila] - 1
		p = mila
	else:
		break
	k += 1
print(max(ans))


def prod(a):
	res = 1
	for i in range(len(a)):
		if a[i] == '0':
			continue
		res *= ord(a[i]) - ord('0')
	return res

def main():
	n = input()
	a = list(n)
	_max = prod(a)
	for pos in range(len(a)):
		if a[pos] == '0':
			break
		b = a.copy()
		b[pos] = chr(ord(b[pos]) - 1)
		for i in range(pos + 1, len(b)):
			b[i] = '9'
		_max = max(_max, prod(b))
	print(_max)
main()


s = list((ord(x) - ord('0') for x in input()))
result = 0

def prod(s):
	i = 0
	if s[0] == 0:
		i = 1
	tmp = 1
	for j in range(i, len(s)):
		tmp *= s[j]
	return tmp
for i in range(0, len(s) + 1):
	pref = s[0:i]
	if i < len(s):
		pref.append(s[i] - 1)
		for j in range(len(s) - i - 1):
			pref.append(9)
	result = max(result, prod(pref))
print(result)


n = int(input())
sn = str(n)
k = len(sn)
ans = 1
for i in sn:
	ans *= int(i)
for i in range(k - 1):
	n -= 10 ** (i + 1)
	n //= 10 ** (i + 1)
	n *= 10 ** (i + 1)
	n += 10 ** (i + 1) - 1
	if n < 0:
		break
	sn = str(n)
	res = 1
	for i in sn:
		res *= int(i)
	ans = max(res, ans)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def bfs(g, st):
	visited = [-1] * len(g)
	visited[st] = 0
	queue = []
	queue.append(st)
	new = []
	while len(queue) != 0:
		s = queue.pop()
		new.append(s)
		for i in g[s]:
			if visited[i] == -1:
				visited[i] = visited[s] + 1
				queue.append(i)
	return visited

def dfsusingstack(v, st):
	d = deque([])
	visited = [0] * len(v)
	d.append(st)
	new = []
	visited[st] = 1
	while len(d) != 0:
		curr = d.pop()
		new.append(curr)
		for i in v[curr]:
			if visited[i] == 0:
				visited[i] = 1
				d.append(i)
	return new

def sieve(a, n):
	for i in range(3, n + 1, 2):
		a[i] = 1
	for i in range(3, n + 1, 2):
		for j in range(i * i, n + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	a = list(inp())
	for i in range(0, len(a)):
		a[i] = int(a[i])
	n = len(a)
	ans = 1
	for i in range(1, n):
		ans *= 9
	temp = 1
	for i in range(n):
		temp *= a[i]
	ans = max(ans, temp)
	for i in range(n):
		if a[i] > 1:
			temp = 1
			for j in range(i):
				temp *= a[j]
			temp *= a[i] - 1
			for j in range(i + 1, n):
				temp *= 9
			ans = max(ans, temp)
	print(ans)
testcase(1)


def numb(chis):
	numb = 1
	for i in str(chis):
		numb *= int(i)
	return numb

def check(a, b):
	mass = []
	b = str(b)
	for i in range(len(b) - 1):
		if b[i] != '0':
			if int(b[:i] + str(int(b[i]) - 1) + '9' * (len(b) - i - 1)) >= a:
				mass.append(int(b[:i] + str(int(b[i]) - 1) + '9' * (len(b) - i - 1)))
	mass.append(b)
	maxxx = 0
	maxxxx = 0
	for i in mass:
		k = numb(i)
		if k >= maxxxx:
			maxxx = i
			maxxxx = k
	return maxxx
n = int(input())
print(numb(check(1, n)))


word = input()
num = int(word)
elise = [int(number) for number in list(word)]
eliseList = []
for i in range(len(elise) - 1, 0, -1):
	eliseList.append(elise[:])
	elise[i] = 9
	elise[i - 1] -= 1
eliseList.append(elise[:])
result = 0
for j in eliseList:
	f = 1
	stuff = True
	for k in j:
		if stuff == True and k == 0:
			pass
		else:
			f *= k
			stuff = False
	if f > result:
		result = f
print(result)


def fun(l):
	sum1 = 1
	for i in l:
		sum1 *= i
	return sum1
l = [int(i) for i in input()]
ans = max(fun(l), fun([9] * (len(l) - 1)))
for i in range(len(l)):
	ans = max(ans, fun(l[:i] + [l[i] - 1] + (len(l) - i - 1) * [9]))
print(ans)


n = list(map(int, input()))
m = 1
for (i, d) in enumerate(reversed(n)):
	if i == 0:
		m = d
	else:
		m = max(d * m, max(d - 1, 1) * 9 ** i)
print(m)


from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

def check(a):
	ans = 1
	a = int(a)
	while a:
		ans *= a % 10
		a //= 10
	return ans

def ans(a, b, cnt):
	max_right = 0
	ans_right = 0
	max_mid = 0
	ans_mid = 0
	x = 9 ** cnt
	ans_right = b + cnt * '9'
	max_right = check(ans_right)
	a = int(a)
	b = int(b)
	while a % 10 != 9:
		a += 1
	while b % 10 != 9:
		b -= 1
	if a > b:
		return (max_right, ans_right)
	a = str(a)
	b = str(b)
	a = (len(b) - len(a)) * '0' + a
	if a != b and len(a) > 1:
		(max_mid, ans_mid) = ans(a[:-1], b[:-1], cnt + 1)
	else:
		ans_mid = b + '9' * cnt
		max_mid = check(ans_mid)
	if max_right > max_mid:
		return (max_right, ans_right)
	return (max_mid, ans_mid)
mass_b = [1]

def get(a, b):
	nonlocal mass_b
	a = str(a)
	b = str(b)
	a = (len(b) - len(a)) * '0' + a
	for i in b:
		mass_b.append(mass_b[-1] * int(i))
	return int(ans(a, b, 0)[1])

def main():
	a = input()
	print(check(get(1, a)))
main()


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(ans, multip) = (1, 1)
digits = [int(x) for x in str(RI())]
digits = digits[::-1]
for digit in digits:
	ans = max(digit * ans, digit * multip - multip, multip)
	multip *= 9
print(ans)


n = str(input())
m = len(n)
if int(n[0]) > 1:
	test1 = (int(n[0]) - 1) * 9 ** (m - 1)
else:
	test1 = 9 ** (m - 1)
tem = int(n[0])
for i in range(1, m):
	test = 1
	if int(n[i]) > 1:
		test = tem * (int(n[i]) - 1) * 9 ** (m - i - 1)
	elif int(n[i]) == 0:
		break
	tem *= int(n[i])
	test1 = max(test1, test)
test = 1
for i in range(m):
	test *= int(n[i])
test1 = max(test, test1)
print(test1)


def all_nine(x):
	res = ''
	for i in range(x):
		res += '9'
	return res

def product(x):
	res = 1
	for c in x:
		res *= int(c)
	return res

def answer(n):
	if len(n) == 1:
		return n
	opt = [all_nine(len(n) - 1)]
	if int(n[0]) > 1:
		new_opt = ''
		new_opt += str(int(n[0]) - 1)
		new_opt += all_nine(len(n) - 1)
		opt.append(new_opt)
	new_opt = str(n[0])
	new_opt += answer(n[1:])
	opt.append(new_opt)
	opt.sort(key=product)
	return opt[-1]
n = input()
print(product(answer(n)))


nu = input()
no = int(nu)
lis = [int(x) for x in nu]
a = len(lis)
pro = j = pr = 1
if a == 1:
	print(*lis)
elif a == 2:
	pro = max(lis[0] * lis[1], (lis[0] - 1) * 9, 9)
	print(pro)
else:
	if lis[-1] == 0:
		no -= 1
		lis = [int(x) for x in str(no)]
	a = len(lis)
	for i in range(a):
		pro *= lis[i]
	for i in range(1, a):
		j *= lis[i - 1]
		p = j * (lis[i] - 1) * 9 ** (a - i - 1)
		pr = max(pro, p, pr)
	ans = max(pro, (lis[0] - 1) * 9 ** (a - 1), 9 ** (a - 1), pr)
	print(ans)


def nir(n):
	if n < 10:
		return max(1, n)
	else:
		p = nir(n // 10) * (n % 10)
		q = nir(n // 10 - 1) * 9
		return max(p, q)
n = int(input())
ans = nir(n)
print(ans)


n = list(input())
for i in range(len(n)):
	n[i] = int(n[i])
mas = [n]
for i in range(len(n)):
	if n[i] == 0:
		break
	mmm = n.copy()
	mmm[i] -= 1
	for j in range(i + 1, len(n)):
		mmm[j] = 9
	mas.append(mmm)
ans = 0
for i in range(len(mas)):
	ch = 1
	for j in range(len(mas[i])):
		if j == 0 and mas[i][j] == 0:
			continue
		ch *= mas[i][j]
	ans = max(ans, ch)
print(ans)


import sys
import math as mt
I = lambda : list(map(int, input().split()))
(n,) = I()
if n < 10:
	print(n)
	sys.exit()

def s(x):
	ans = 1
	if x < 10:
		return x
	for i in str(x):
		ans *= int(i)
	return ans
t = s(n)
for i in range(len(str(n)) - 1):
	m = 10 ** (i + 1)
	nn = n
	nn = nn - n % m - 1
	t = max(t, s(nn))
print(t)


def f(x):
	if x[0] == '1':
		return 9 ** (len(x) - 1)
	elif len(x) == 1:
		return int(x)
	else:
		return max((int(x[0]) - 1) * 9 ** (len(x) - 1), int(x[0]) * f(x[1:]))
n = input()
print(f(n))


import math
import bisect

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
n = f()
res = 1
s = str(n)
n = len(s)

def func(t):
	res = 1
	for i in range(len(str(t))):
		res *= t % 10
		t = t // 10
	return res
a = 1
for i in range(n):
	a *= int(s[i])
cl = [a]
k = int(s)
i = 0
while k > 0:
	k -= k % 10 + 1
	if k > 0:
		cl.append(func(k) * 9 ** i)
	k = k // 10
	i += 1
print(max(cl))


def dp(n):
	answer = 1
	for i in str(n):
		answer *= int(i)
	return answer
while True:
	n = int(input())
	answer = dp(n)
	for i in range(0, len(str(n))):
		answer = max(answer, dp((n // 10 ** i - 1) * 10 ** i + int('0' + '9' * i)))
	print(answer)
	break


def sucin(aa):
	b = str(aa)
	r = 1
	for x in range(len(b)):
		r = r * int(b[x])
	return r

def take_num(aa):
	i = 1
	while aa > 0:
		aa = aa // 10
		i *= 10
		if aa > 0:
			b.append(aa * i - 1)
a = int(input())
b = [a]
take_num(a)
print(max([sucin(x) for x in b]))


def product(num):
	num = str(num)
	prod = 1
	for x in num:
		prod *= int(x)
	return prod
n = input()
if int(n) < 10:
	print(n)
else:
	div = 10
	num = int(n)
	lsi = []
	for _ in range(1, len(n)):
		lsi.append(num - num % div - 1)
		div *= 10
	bar = [product(num)]
	for x in lsi:
		bar.append(product(x))
	print(max(bar))


def s(a):
	a = list(a)
	while a and a[0] == '0':
		a.pop(0)
	prod = 1
	for i in a:
		prod *= int(i)
	return prod
a = input()
ans = [s(a), a]
for i in range(len(a) - 1, -1, -1):
	if a[i] == '0':
		continue
	b = a[:i] + str(int(a[i]) - 1) + '9' * len(a[i + 1:])
	if s(b) > ans[0]:
		ans = [s(b), b]
print(int(ans[0]))


def mult(n):
	a = 1
	while n != 0:
		b = n % 10
		a *= b
		n //= 10
	return a

def f(n):
	if n < 9:
		return 0
	n //= 10
	i = 10
	b = 9
	while n != 0:
		if n % 10 == 0:
			n -= 1
			b += n * i
			n = 0
		else:
			b += (n - 1) * i
			n = 0
	return b
n = int(input())
ans = mult(n)
i = 0
k = f(n)
while i <= len(str(n)) and k < n:
	i += 1
	r = mult(k)
	ans = max(r, ans)
	k = f(k // 10 ** i) * 10 ** i + int('0' + '9' * i)
print(ans)


n = input()
if int(n) > 9:
	a = [(str(int(n[:i + 1]) - 1) + '9' * (len(n) - i - 1)).lstrip('0') for i in range(len(n))]
	a.append(n)
	best = 0
	for val in a:
		s = 1
		if int(val) <= int(n):
			for i in val:
				s *= int(i)
		best = max(s, best)
	print(best)
else:
	print(n)


import os
import sys
from io import BytesIO, IOBase
(sys.stdout, stream) = (IOBase(), BytesIO())
sys.stdout.flush = lambda : os.write(1, stream.getvalue()) and (not stream.truncate(0)) and stream.seek(0)
sys.stdout.write = lambda s: stream.write(s.encode())
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = int(input())

	def solve(n):
		if len(n) == 1:
			return int(n)
		return max(int(n[0]) * solve(n[1:]), (int(n[0]) - 1) * 9 ** int(len(n[1:])), 9 ** int(len(n[1:])))
	print(solve(str(n)))
main()


def solve(n):
	if n < 10:
		return n
	digit = int(str(n)[0])
	ans1 = digit * solve(int(str(n)[1:]))
	ans2 = max(1, digit - 1) * 9 ** (len(str(n)) - 1)
	return max(ans1, ans2)
n = int(input())
print(solve(n))


def prod(num):
	prod = num % 10
	num = num // 10
	while num > 0:
		prod = prod * (num % 10)
		num = num // 10
	return prod
num = int(input())
numx = str(num)
l = len(numx)
maxx = prod(num)
for i in range(l):
	try:
		intnum = int(numx[:l - i - 1] + str(int(numx[l - i - 1]) - 1) + '9' * i)
		pr = prod(intnum)
		if intnum <= num and pr > maxx:
			maxx = pr
	except:
		pass
print(maxx)


import sys
n = int(sys.stdin.readline())
if n < 10:
	print(n)
else:
	answ = []
	i = 0
	k = len(str(n))
	while i <= k:
		while n % 10 ** (i + 1) // 10 ** i != 9:
			ans = 1
			for j in str(n):
				ans *= int(j)
			n -= 10 ** i
			if n < 0:
				break
			answ.append(ans)
		ans = 1
		if n < 0:
			break
		for j in str(n):
			ans *= int(j)
		answ.append(ans)
		k = len(str(n))
		i += 1
	print(max(answ))


def main():
	n = int(input())
	a = list(map(int, list(str(n))))
	ret = 1
	for i in range(len(a)):
		ret *= a[i]
	curr_num = 0
	for i in range(len(a)):
		curr_num = curr_num * 10 + a[i]
		if curr_num - 1 <= 0:
			temp_list = []
		else:
			temp_list = list(map(int, list(str(curr_num - 1))))
		for j in range(len(a) - i - 1):
			temp_list.append(9)
		temp_ret = 1
		for j in range(len(temp_list)):
			temp_ret *= temp_list[j]
		ret = max(ret, temp_ret)
	print(ret)
main()


from collections import Counter
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))

def solve(x):
	if x[0] == '1':
		return 9 ** (len(x) - 1)
	elif len(x) == 1:
		return int(x)
	else:
		return max((int(x[0]) - 1) * 9 ** (len(x) - 1), int(x[0]) * solve(x[1:]))
n = input('')
print(solve(n))


from collections import defaultdict as DD
from bisect import bisect_left as BL
from bisect import bisect_right as BR
from itertools import combinations as IC
from itertools import permutations as IP
from random import randint as RI
import sys
MOD = pow(10, 9) + 7

def IN(f=0):
	if f == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())

def fnx(n):
	f = list(str(n))
	f = [int(u) for u in f]
	r = 1
	for i in f:
		r *= i
	return r
n = IN(1)
if len(str(n)) == 1:
	print(n)
else:
	f = list(str(n))
	f = [int(u) for u in f]
	k = len(f)
	ans = []
	Y = n
	for i in range(k):
		ans.append(fnx(n * pow(10, i) - 1))
		n = n // 10
	print(max(max(ans), fnx(Y)))


num = list(input())
temp = []
result = []

def init(temp):
	temp.clear()
	for i in num:
		temp.append(9)

def val(a):
	x = 1
	for i in a:
		if i == 0 or i == '0':
			x = x * (int(i) + 1)
		else:
			x = x * int(i)
	return x
result.append(val(num))
for i in range(0, len(num)):
	for j in range(0, i):
		if j == i - 1:
			temp[j] = int(num[j]) - 1
		else:
			temp[j] = int(num[j])
	result.append(val(temp))
	init(temp)
print(max(result))


n = int(input())

def ok(n):
	if n < 10:
		return n
	s = str(n)
	return max(int(s[0]) * ok(int(s[1:])), (1 if s[0] == '1' else int(s[0]) - 1) * 9 ** (len(s) - 1))
print(ok(n))


def run():
	n = input()
	ls = [int(i) for i in n]
	ans = evall(ls)
	i = len(ls) - 1
	while i > 0:
		if ls[i] != 9:
			ls[i] = 9
			if ls[i - 1] > 0:
				ls[i - 1] -= 1
			ans = max(ans, evall(ls))
		i -= 1
	return ans

def evall(ls):
	mul = 1
	for s in ls:
		if s <= 0:
			continue
		mul *= int(s)
	return mul
print(run())


n = list(map(int, input()))
res = 1
for a in n:
	res *= a
for i in range(len(n)):
	if n[i] == 0:
		break
	n[i] -= 1
	res_ = 1
	for j in range(len(n)):
		if j == 0:
			res_ *= max(1, n[j])
		elif j <= i:
			res_ *= n[j]
		else:
			res_ *= 9
	res = max(res_, res)
	n[i] += 1
print(res)


def ans(n):
	if n == 0:
		return 1
	if n <= 9:
		return n
	return max(n % 10 * ans(n // 10), 9 * ans(n // 10 - 1))
n = int(input())
print(ans(n))


n = int(input())
d = str(n)
a = []
t = n
if n < 10:
	print(n)
else:
	flag = 0
	while n > 9:
		a.append(9)
		t = n % 10
		if t != 9:
			flag = 1
		n //= 10
	s = n
	a.append(n - 1)
	if a[-1] != 0:
		a1 = 1
		a2 = 1
		if flag == 0 or len(d) < 3:
			for i in range(1, s + 1):
				for j in range(1, 10):
					if i == s and j <= t or i < s:
						if i * j > a1 * a2:
							a1 = i
							a2 = j
		else:
			for i in range(1, s + 1):
				for j in range(1, 10):
					if i == s and j < t or i < s:
						if i * j > a1 * a2:
							a1 = i
							a2 = j
		a[-1] = a1
		a[-2] = a2
	else:
		a[-1] = 1
	ans = 1
	if len(d) > 2:
		if a[-3] == 9 and a[-2] == 7 and (d[1] >= '8') and (d[2] >= '8'):
			a[-2] = 8
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 6 and (d[1] >= '7') and (d[2] >= '8'):
			a[-2] = 7
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 5 and (d[1] >= '6') and (d[2] >= '8'):
			a[-2] = 6
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 4 and (d[1] >= '5') and (d[2] >= '8'):
			a[-2] = 5
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 3 and (d[1] >= '4') and (d[2] >= '8'):
			a[-2] = 4
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 2 and (d[1] >= '3') and (d[2] >= '8'):
			a[-2] = 3
			a[-3] = 8
		elif a[-3] == 9 and a[-2] == 1 and (d[1] >= '2') and (d[2] >= '8'):
			a[-2] = 2
			a[-3] = 8
	for i in a:
		ans *= i
	print(ans)


nr = int(input())

def prod_nr(nr):
	if not nr:
		return 0
	d = 1
	while nr:
		d *= nr % 10
		nr = nr // 10
	return d

def sum_nr(nr):
	d = 0
	while nr:
		d += nr % 10
		nr = nr // 10
	return d
numbers = [nr]
count = 0
nines = 0
while nr:
	nr = nr // 10
	nines = nines * 10 + 9
	count += 1
	if not nr:
		break
	numbers.append((nr - 1) * 10 ** count + nines)
max_nr = 0
_max = 0
for nr in numbers:
	res = prod_nr(nr)
	if res > max_nr:
		max_nr = res
		_max = nr
print(prod_nr(_max))


a = [int(i) for i in input()]

def product(x):
	tt = 1
	for i in x:
		tt *= i
	return tt
maximum = product(a)
for i in range(len(a)):
	nombre = a[:i] + [a[i] - 1] + [9] * (len(a) - i - 1)
	index = 0
	while index < len(a) and (not nombre[index]):
		index += 1
	produit = product(nombre[index:])
	maximum = max(maximum, produit)
print(maximum)


def f(a):
	if a < 10:
		if a == 0:
			a = 1
		return max(1, a)
	return max(a % 10 * f(a // 10), 9 * f(a // 10 - 1))
a = int(input())
print(f(a))


def multi(nu):
	r = 1
	for x in str(nu):
		r *= int(x)
	return r
n = int(input())
res = multi(n)
for i in range(100):
	aa = n - n % 10 ** i - 1
	if aa >= 0:
		res = max(res, multi(aa))
print(res)


def max_product(n):
	if n < 10:
		return n
	short_n = int(str(n)[1:])
	length_short = len(str(n)) - 1
	first = int(str(n)[0])
	if first == 1:
		return 9 ** length_short
	if short_n == 0:
		return (first - 1) * 9 ** length_short
	return max((first - 1) * 9 ** length_short, first * max_product(short_n))
n = int(input())
print(max_product(n))


def find(n):
	n = list(map(int, str(n)))
	ans = 1
	for x in n:
		ans *= x
	return ans
n = int(input())
s = str(n)
l = len(s)
ans = find(n)
k = 10 ** (l - 1)
while k:
	ans = max(ans, find(n // k * k - 1))
	k //= 10
print(ans)


n = input()
x = len(n)
if x == 1:
	print(n)
else:
	i = int(n)
	product = 1
	while i != 0:
		product = product * (i % 10)
		i = i // 10
	max = product
	i = 0
	while i < x:
		p = n[0:i + 1]
		p = int(p) * 10 ** (x - 1 - i) - 1
		product = 1
		while p != 0:
			product = product * (p % 10)
			p = p // 10
		if max < product:
			max = product
		i = i + 1
	print(max)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = dgl()
nl = len(n)
ans = 1
for i in n:
	ans *= i
if n[0] == 1:
	ans = max(ans, pow(9, nl - 1))
for i in range(nl - 1):
	t = 1
	for j in range(i):
		t *= n[j]
	t *= n[i] - 1
	for j in range(i + 1, nl):
		t *= 9
	ans = max(ans, t)
print(ans)


n = int(input())
num = len(str(n))
if n == int('9' * num):
	print(9 ** num)
elif n < 10:
	print(n)
else:
	alth = '01234567891'
	ans = 9 ** (num - 1)
	num2 = list(str(n))
	for i in range(num):
		if num2[i] == '0':
			num2[i] = '9'
			i -= 1
			for j in range(i + 2, num):
				num2[j] = '9'
			while i > 0 and (num2[i] == '0' or num2[i] == '1'):
				num2[i] = '9'
				i -= 1
			num2[i] = alth[alth.find(num2[i]) - 1]
			break
	num3 = 1
	for j in range(num):
		num3 *= int(num2[j])
	ans = max(num3, ans)
	for i in range(num - 1, 0, -1):
		num2[i] = '9'
		num2[i - 1] = alth[alth.find(num2[i - 1]) - 1]
		num3 = 1
		for j in range(num):
			num3 *= int(num2[j])
		ans = max(num3, ans)
	print(ans)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def cal(self, s):
		if len(s) == 1:
			return s[0]
		if s[0] == 0:
			return self.cal(s[1:])
		v = 1
		for c in s:
			v *= c
		return v

	def solve(self):
		s = [ord(x) - ord('0') for x in self.next()]
		v = self.cal(s)
		l = len(s)
		for i in range(1, l):
			s[l - i] = 9
			if s[l - i - 1] != 0:
				s[l - i - 1] -= 1
				v = max(v, self.cal(s))
		print(v)
Main().solve()


def prod(n):
	res = 1
	while n:
		res *= n % 10
		n //= 10
	return res
string = input()
if len(string) == 1:
	print(string)
else:
	trad = str(int(string[0]) - 1)
	n = len(string)
	for i in range(n - 1):
		trad += '9'
	s = ''
	for i in range(n - 1):
		if string[i] > string[i + 1]:
			s += str(int(string[i]) - 1)
			break
		s += string[i]
	for i in range(n - len(s)):
		s += '9'
	num = int(s)
	if num > int(string):
		num = 0
	ans = max(prod(int(trad)), prod(num), prod(int(string)))
	print(ans)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [_ for _ in input().strip().split()]
n = read()
answ = 1
for c in n:
	answ *= int(c)
ans = [answ]
for i in range(len(n) - 1):
	answ = 1
	new = str(int(n[:i + 1]) - 1)
	new += '9' * (len(n) - i - 1)
	new = str(int(new))
	for c in new:
		answ *= int(c)
	ans.append(answ)
print(max(ans))


def p(n):
	k = str(n)
	f = 1
	for i in k:
		f *= int(i)
	return f
n = int(input())
k = str(n)
l = len(k)
mx = p(n)
for i in range(1, l):
	new = n - int(k[l - i:]) - 1
	mx = max(p(new), mx)
print(mx)


n = int(input())
n1 = n
ans = 1
while n1 > 0:
	ans = ans * (n1 % 10)
	n1 = n1 // 10
p = 1
d = 1
z1 = n // 10
while z1 > 0:
	p = 1
	z1 -= 1
	for i in range(d):
		p *= 9
	z2 = z1
	while z2 > 0:
		p *= z2 % 10
		z2 = z2 // 10
	ans = max(ans, p)
	d += 1
	z1 = z1 // 10
print(ans)


import sys
from functools import reduce
import copy

def multiply(numstr):
	product = []
	ni = int(numstr, 10)
	num = [int(m) for m in list(numstr)]
	if len(num) == 1:
		return num[0]
	tmp = 1
	for n in num:
		tmp *= n
	product.append(tmp)
	for d in range(0, len(num)):
		numtmp = num[:]
		if numtmp[d] - 1 == 0 or numtmp[d] == -1:
			numtmp[d] = 1
		else:
			numtmp[d] = numtmp[d] - 1
		for n in range(d + 1, len(numtmp)):
			numtmp[n] = 9
		tmp = 1
		for n in numtmp:
			if n == 0:
				n = 1
			tmp *= n
		product.append(tmp)
	return max(product)

def nirvana(n):
	ni = int(n, 10)
	if ni % 10 == 0:
		return multiply(str(ni - 1))
	else:
		return multiply(n)

def io():
	given_tests = []
	number = sys.stdin.readline()
	print(nirvana(number.strip()))
io()


n = input()
cifry = [int(x) for x in n]
ind = -1
maxs = 1
s = 1
for c in cifry:
	s *= c
maxs = max(s, maxs)
while ind > -len(cifry):
	if cifry[ind] != 9:
		cifry[ind] = 9
		if cifry[ind - 1] == 0:
			ind -= 1
			continue
		cifry[ind - 1] -= 1
	s = 1
	for c in cifry:
		s *= c
	maxs = max(s, maxs)
	ind -= 1
if cifry[0] == 0:
	cifry[0] = 1
s = 1
for c in cifry:
	s *= c
maxs = max(s, maxs)
print(maxs)


def F(x):
	if x == 0:
		return 1
	if x <= 9:
		return x
	return max(x % 10 * F(x // 10), 9 * F(x // 10 - 1))
n = int(input())
print(F(n))


def product(number):
	result = 1
	for digit in number:
		result *= int(digit)
	return result
number = int(input())
ans = product(str(number))
multiplier = 1
while multiplier < number:
	evaluate = product(str(number // multiplier * multiplier - 1))
	ans = ans if ans > evaluate else evaluate
	multiplier *= 10
print(ans)


n = input()
m = 0
l = [int(x) for x in list(n)]
nlen = len(l)
for i in range(nlen):
	p = 1
	if i != 0 and (l[i] == 1 or l[i] == 0):
		continue
	if i == 0 and l[i] == 1:
		for j in range(1, nlen):
			p *= 9
		if p > m:
			m = p
		continue
	if i == nlen - 1:
		for j in range(nlen):
			p *= l[j]
		if p > m:
			m = p
		continue
	for j in range(nlen):
		if j > i:
			p *= 9
			continue
		if i != j:
			p *= l[j]
		elif l[i] != 0 and l[i] != 1:
			p *= l[j] - 1
		else:
			p *= 9
	if p > m:
		m = p
print(m)


s = input()
ans = 1
for x in s:
	ans *= int(x)
ans = max(ans, 9 ** (len(s) - 1))
tmp = 1
for i in range(len(s)):
	v = int(s[i])
	ans = max(ans, tmp * (v - 1) * 9 ** (len(s) - i - 1))
	tmp *= v
print(ans)


from functools import *
n = input()
m = 0
for i in range(1, len(n)):
	if n[i - 1] == '0':
		continue
	m = max(m, reduce(lambda a, b: a * b, map(int, list(str(int(n[:i - 1] + str(int(n[i - 1]) - 1) + '9' * (len(n) - i)))))))
m = max(m, reduce(lambda a, b: a * b, map(int, list(n))))
print(m)


t = list(map(int, list(input())))
k = 0
ans = []
m = len(t)
p = m - 1
lu = 9
while p != -1:
	ppo = 1
	initial = 0
	for i in range(m):
		if t[i] == 0 and initial == 0:
			continue
		else:
			initial = 1
			ppo *= t[i]
	ans.append(ppo)
	ma = -5
	for i in range(p, -1, -1):
		if t[i] != 0:
			ma = i
			break
	if ma != -5:
		for i in range(ma + 1, m, 1):
			t[i] = lu
		t[ma] = t[ma] - 1
		p = ma
	else:
		break
	k += 1
print(max(ans))


a = list(input())

def pro(a):
	m = 1
	c = 0
	for i in range(len(a)):
		if int(a[i]) == 0 and c == 0:
			m = 1
		elif int(a[i]) != 0:
			c = 1
			m = m * int(a[i])
		else:
			m = 0
	return m
ma = pro(a)
b = ['9' for i in range(len(a))]
for i in range(len(a)):
	if a[i] == '0':
		pass
	else:
		b[i] = chr(ord(a[i]) - 1)
		ma = max(ma, pro(b))
		b[i] = a[i]
print(ma)


n = input()
k = 0
for i in range(len(n)):
	m = 1
	for j in range(i):
		m *= int(n[j])
	b = int(n[i]) - 1
	if b == 0:
		b = 1
	m *= b
	for j in range(i + 1, len(n)):
		m *= 9
	k = max(m, k)
a = 1
for j in range(0, len(n)):
	a *= int(n[j])
k = max(a, k)
print(k)


def f(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	l.reverse()
	ll = len(l)
	p1 = 1
	pl = []
	for i in range(ll):
		p2 = l[i] if i == ll - 1 else max(l[i] - 1, 1) * 9 ** (ll - i - 1)
		pl.append(p1 * p2)
		p1 *= l[i]
	return max(pl)
n = int(input())
print(f(n))


from __future__ import division, print_function
import io
import os
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from cStringIO import StringIO
	from future_builtins import ascii, filter, hex, map, oct, zip
else:
	from io import BytesIO as StringIO
(sys.stdout, stream) = (io.IOBase(), StringIO())
sys.stdout.flush = lambda : os.write(1, stream.getvalue()) and (not stream.truncate(0)) and stream.seek(0)
sys.stdout.write = stream.write if sys.version_info[0] < 3 else lambda s: stream.write(s.encode())
(input, flush) = (sys.stdin.readline, sys.stdout.flush)
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = list(map(int, str(int(input()) + 1)))
	l = len(n)
	p = 1
	m = (n[0] - 1 if n[0] != 1 else 1) * 9 ** (l - 1)
	for (i, j) in enumerate(n):
		if j == 0:
			continue
		m = max(m, p * (j - 1) * 9 ** (l - i - 1))
		p *= j
	print(m)
main()


def rec(n):
	if len(str(n)) == 1:
		return n
	same = rec(n // 10)
	lesser = rec(n // 10 - 1)
	return max(9, same * (n % 10), lesser * 9)
print(rec(int(input())))


import math
import sys
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def mul(s):
	r = 1
	for i in s:
		r *= int(i)
	return r
n = ii()
s = str(n)
l = len(s)
r = mul(s)
for i in range(l - 1):
	t = s[:i]
	if s[i] == '0' or (s[i] == '1' and i == 0):
		t += '9' * (l - i - 1)
	else:
		t += str(int(s[i]) - 1) + '9' * (l - i - 1)
	r = max(r, mul(t))
print(r)


number = input().strip()

def mul(n):
	ans = 1
	for i in n:
		ans *= int(i)
	return ans
possibilities = [mul(number)]
for i in range(1, len(number)):
	possibilities.append(mul(str(int(number) - int(number[i:]) - 1)))
print(max(possibilities))


n = int(input())

def pmax(n):
	(q, r) = divmod(n, 10)
	if n < 10:
		return n
	elif r == 0:
		return pmax(n - 1)
	elif r == 9:
		return 9 * pmax(q)
	else:
		return max(pmax(n - r - 1), r * pmax(q))
print(pmax(n))


n = int(input())
z = n
a = []
p = 1
ans = 1
while z > 0:
	a.append(z % 10)
	z = z // 10
if len(a) == 1:
	ans = n
else:
	for i in a:
		p *= i
	ans = p
	j = 1
	while j < len(a):
		for i in range(j):
			a[i] = 9
		a[i + 1] -= 1
		if a[len(a) - 1] == 0:
			a.pop()
		j += 1
		pro = 1
		for i in range(len(a)):
			pro = pro * a[i]
		ans = max(ans, pro)
print(ans)


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce

def solution(n):
	val = [str(i) for i in str(n)]
	if len(val) < 2:
		return n
	else:
		best = reduce(lambda x, y: int(x) * int(y), val)
		for i in range(len(val) - 2, 0, -1):
			val[i + 1] = '9'
			if val[i] == '0':
				continue
			val[i] = str(int(val[i]) - 1)
			best = max(best, reduce(lambda x, y: int(x) * int(y), val))
		if val[0] == '1':
			val = ['9' for i in range(len(val) - 1)]
		else:
			val = [str(int(val[0]) - 1)] + ['9' for i in range(len(val) - 1)]
		if len(val) == 1:
			best = max(best, int(val[0]))
		else:
			best = max(best, reduce(lambda x, y: int(x) * int(y), val))
	return best
n = [int(val) for val in sys.stdin.readline().split()][0]
print(solution(n))


def productt(ss):
	if ss[0] == '0':
		return productt(ss[1:])
	if '0' in ss:
		return 0
	p = 1
	for i in map(int, ss):
		p = p * i
	return p

def getListNumMax(ss):
	maxi = 0
	for i in range(1, len(ss)):
		nn = str(int(ss[:i]) - 1) + '9' * (len(ss) - i)
		maxi = max(maxi, productt(nn))
	return maxi
s = str(input())
sn = int(s)
if sn < 10:
	print(sn)
else:
	num = str(int(s[0]) - 1) + '9' * (len(s) - 1)
	numn = int(num)
	maxi = max(productt(s), productt(str(sn - sn % 10 - 1)), productt(num))
	print(max(maxi, getListNumMax(s)))


def multiplication(a):
	m = a[0]
	for i in range(1, len(a)):
		m *= a[i]
	return m
n = int(input())
answs = []
if n < 9:
	answs.append(n)
else:
	answs.append(multiplication(list(map(int, *str(n).split()))))
	for i in range(len(str(n)) * 10):
		for j in range(len(str(n)) - 1, -1, -1):
			if str(n)[j] != '9':
				n -= 10 ** (len(str(n)) - j - 1)
				break
		answs.append(multiplication(list(map(int, *str(n).split()))))
print(max(answs))


import math

def power(s):
	if int(s[0]) - 1 == 0:
		return math.pow(9, len(s) - 1)
	else:
		return (int(s[0]) - 1) * math.pow(9, len(s) - 1)

def mult(s):
	res = 1
	for i in range(len(s)):
		res *= int(s[i])
	return res
s = input()
list = []
(i, n) = (0, len(s))
for i in range(n):
	k = int(mult(s[0:i]) * power(s[i:]))
	list.append(k)
list.append(mult(s))
print(max(list))


n = int(input())
n += 1
n = list(str(n))
if len(n) == 1:
	print(int(n[0]) - 1)
	exit()
mi = 9 ** (len(n) - 1)
for i in range(1, len(n) + 1):
	if n[i - 1] != 0:
		new = 1
		for l in range(i - 1):
			new *= int(n[l])
		new *= int(n[i - 1]) - 1
		new *= 9 ** (len(n) - i)
		mi = max(mi, new)
print(mi)


a = input()
if len(a) == 1:
	print(int(a))
else:
	b = []
	p = 1
	for i in range(len(a)):
		b.append(a[i])
		p = p * int(a[i])
		li = b.copy()
	for i in range(1, len(b)):
		t = 1
		l = b.copy()
		if l[i] != '1':
			l[i] = str(int(l[i]) - 1)
		''.join(l)
		for j in range(i + 1):
			t = t * int(l[j])
		t = t * pow(9, len(b) - i - 1)
		if t > p:
			p = t
			li = l.copy()
	t = 1
	l = b.copy()
	if b[0] != '1':
		l[0] = str(int(l[0]) - 1)
		t = int(l[0])
		t = t * pow(9, len(b) - 1)
		if t > p:
			p = t
			li = l.copy()
	else:
		l.remove(l[0])
		t = pow(9, len(b) - 1)
		if t > p:
			p = t
			li = l.copy()
	li = ''.join(li)
	print(p)


n = list(map(int, input()))
result = 1
for j in n:
	if j != 0:
		result *= j
if len(n) != 1:
	for i in range(len(n) - 1):
		if n[len(n) - i - 1] < 9:
			n[len(n) - i - 1] = 9
			n[len(n) - i - 2] -= 1
		temp = 1
		for j in n:
			if j != 0:
				temp *= j
		result = max(result, temp)
else:
	result = n[0]
print(result)


from functools import reduce

def calculate(n):
	return reduce(lambda x, y: x * y, map(int, [i for i in str(n)]))

def main():
	n = int(input())
	if n < 10:
		print(n)
	else:
		bigger_result = calculate(n)
		s = str(n)
		for i in range(1, len(s)):
			number = s[:-i] + '0' * i
			number = int(number) - 1
			if number < 0:
				break
			bigger_result = max(bigger_result, calculate(number))
		print(bigger_result)
main()


def prod(num):
	if num == 0:
		return 1
	if num <= 9:
		return num
	return max(num % 10 * prod(num // 10), 9 * prod(num // 10 - 1))
n = int(input())
print(prod(n))


def ProductOfDigits(a):
	a = str(int(a))
	Product = 1
	for i in a:
		Product *= int(i)
	return Product
n = int(input())
a = str(n)
Size = len(a)
if n == int('1' + '0' * (Size - 1)):
	print(9 ** (Size - 1))
	exit()
Ar = []
Ar.append(ProductOfDigits(a))
for i in range(Size):
	Ar.append(ProductOfDigits(str(int(a[:i + 1]) - 1) + '9' * (Size - i - 1)))
print(max(Ar))


def product(x):
	prod = 1
	while x:
		prod *= x % 10
		x //= 10
	return prod

def findNumber(n):
	b = str(n)
	ans = n
	for i in range(len(b)):
		if b[i] == '0':
			continue
		numb = list(b)
		numb[i] = str(int(numb[i]) - 1)
		for j in range(i + 1, len(numb)):
			numb[j] = '9'
		this = 0
		for c in numb:
			this = this * 10 + int(c)
		if product(ans) < product(this):
			ans = this
	return product(ans)
n = int(input())
print(findNumber(n))


def prod(lst):
	if lst[0] == 0:
		lst = lst[1:]
	pr = 1
	for i in lst:
		pr *= i
	return pr
n = [int(i) for i in input()]
if len(n) == 1:
	exit(print(*n))
ans = prod(n)
for k in range(len(n)):
	a = n[:]
	a[k] -= 1
	for i in range(k + 1, len(n)):
		a[i] = 9
	ans = max(ans, prod(a))
print(ans)


x = int(input())

def numDigits(r):
	m = str(r)
	return len(m)

def prodDigits(r):
	m = str(r)
	k = 1
	for i in range(len(m)):
		k *= int(m[i])
	return k
l = []
for i in range(numDigits(x)):
	l.append(prodDigits(x))
	l.append(prodDigits(x - x % 10 ** i - 1))
print(max(l))


import math
i = int(input())
max = 0
k = len(str(i)) - 1
if i < 10:
	print(i)
else:
	list = []
	p = str(i)
	for m in p:
		list.append(int(m))
	p = list
	m = 1
	for j in p:
		m *= j
	if m > max:
		max = m
	m = 1
	for l in range(k, 0, -1):
		q = i
		minus = i % 10 ** l + 1
		q -= minus
		list = []
		p = str(q)
		for m in p:
			list.append(int(m))
		p = list
		m = 1
		for j in p:
			m *= j
		if m > max:
			max = m
	print(max)


n = int(input())

def f(n):
	s = str(n)
	l = len(s)
	if l == 1:
		return n
	if s[0] == '1':
		return 9 ** (l - 1)
	return max((int(s[0]) - 1) * 9 ** (l - 1), int(s[0]) * f(int(s[1:])))
print(f(n))


def f(a):
	x = 1
	for i in str(a):
		x *= int(i)
	return x
a = int(input())
ans = f(a)
for i in range(len(str(a))):
	x = (a // 10 ** i - 1) * 10 ** i + (10 ** i - 1)
	ans = max(ans, f(x))
print(ans)


n = int(input())

def mx(n):
	if n < 1:
		return 1 if n == 0 else 0
	x = n % 10
	if x == 9:
		return 9 * mx(n // 10)
	else:
		return max(x * mx(n // 10), 9 * mx(n // 10 - 1))
print(mx(n))


n = int(input())
n0 = n
a = list(map(int, str(n)))
if n < 10:
	print(n)
	exit()
m = 0

def prod(x):
	p = 1
	for i in str(x):
		p *= int(i)
	return p
for i in range(1, len(a)):
	if 10 ** i > n:
		break
	o = n % 10 ** i
	n -= o + 1
	if prod(n) > m:
		m = prod(n)
print(max(m, prod(n0)))


n = int(input())
if n < 10:
	print(n)
else:
	ans = []
	num = 1
	temp = n
	l = list(str(temp))
	for j in l:
		num *= int(j)
	ans.append(num)
	for i in range(1, 10):
		num = 1
		temp = n
		temp -= temp % 10 ** i + 1
		if temp > 0:
			l = list(str(temp))
			for j in l:
				num *= int(j)
			ans.append(num)
	print(max(ans))


def recurse(n):
	if n < 10:
		return max(1, n)
	return max(recurse(n // 10) * (n % 10), recurse(n // 10 - 1) * 9)
n = int(input())
print(recurse(n))


def nirvana(n):
	res = 1
	while n > 0:
		last = n % 10
		res = res * last
		n = int(n / 10)
	return res

def getCandidate(pos, vec_n):
	if vec_n[pos] == 0:
		return -1
	else:
		vec_n[pos] = vec_n[pos] - 1
		for i in range(pos + 1, len(vec_n)):
			vec_n[i] = 9
		return vecToInt(vec_n)

def vecToInt(vec_n):
	ans = 0
	l = len(vec_n)
	for i in range(0, l):
		ans = ans + vec_n[i] * 10 ** (l - 1 - i)
	return ans

def prev_with9(n):
	for i in range(n, 0, -1):
		last = i % 10
		if last == 9:
			return i
	return 0
n = input()
vec_n = []
for i in range(len(n)):
	vec_n.append(int(n[i]))
res = nirvana(int(n))
if len(vec_n) == 1:
	print(vec_n[0])
	exit()
for i in range(len(n) - 2, -1, -1):
	cand = getCandidate(i, vec_n)
	if cand != -1:
		nirv = nirvana(cand)
		if nirv > res:
			res = nirv
print(res)


import copy
n = input()
arr = list(map(int, list(n)))

def find_max(arr):
	if len(arr) == 1:
		return arr[0]
	elif arr[0] < 2:
		return 9 ** (len(arr) - 1)
	else:
		return max(arr[0] * find_max(arr[1:]), (arr[0] - 1) * 9 ** (len(arr) - 1))
print(find_max(arr))


s = input()
l1 = list(s)
if len(s) == 1:
	print(s)
else:
	maxx = 1
	for j in l1:
		maxx *= int(j)
	for i in range(len(l1)):
		s = l1.copy()
		s[i] = str(int(l1[i]) - 1)
		p = 1
		for j in range(len(s)):
			if j <= i:
				if s[j] == '0':
					s[j] = 1
				p *= int(s[j])
			else:
				p *= 9
		if p > maxx:
			maxx = p
	print(maxx)


n = int(input())
ans = 1
cur = 1
now = list(map(int, list(str(n))))
for c in now:
	cur *= c
ans = max(cur, ans)
n = str(n)
for i in range(len(n)):
	cur = 1
	if n[i] != '0':
		for j in range(len(n)):
			if j < i:
				cur *= int(n[j])
			elif j == i:
				cur *= max(int(n[j]) - 1, 1)
			else:
				cur *= 9
		ans = max(cur, ans)
print(ans)


def pro(x):
	if x < 10:
		return max(1, x)
	else:
		return max(pro(x // 10) * (x % 10), pro(x // 10 - 1) * 9)
n = int(input())
print(pro(n))


n = int(input())
d = []
while n > 0:
	d.append(n % 10)
	n //= 10
d = d[::-1]
r = 0
c = 1
k = len(d)
for (i, v) in enumerate(d):
	k -= 1
	if i:
		t = c * (v - 1) * 9 ** k
	else:
		t = c * max(v - 1, 1) * 9 ** k
	r = max(r, t)
	c *= v
print(max(r, c))


def f(l):
	n = len(l)
	if n == 1:
		return l[0]
	nn = pow(9, n - 1)
	res = nn
	for i in range(1, l[0]):
		res = max(res, i * nn)
	res = max(l[0] * f(l[1:]), res)
	return res
x = [*map(int, input())]
print(f(x))


s = input()
n = len(s)
ans = 9 ** (n - 1)
ch = 1
ch1 = 1
for i in range(n):
	d = int(s[i])
	if d != 0:
		ch1 = ch * 9 ** (n - i - 1)
		ch1 = ch1 * (d - 1)
	ch = ch * d
	ans = max(ans, ch1)
ans = max(ans, ch)
print(ans)


n = input()
t = 9 ** (len(n) - 1)
pr = 1
c = 1
for i in range(len(n)):
	pr = pr * int(n[i])
l = [pr]
for i in range(len(n)):
	k = max(int(n[i]) - 1, 1) * t * c
	c = c * int(n[i])
	l.append(k)
	t = t // 9
print(max(l))


def ir():
	return int(input())

def ia():
	return [int(i) for i in input().split()]

def di():
	return list(input())
a = di()
a = [int(e) for e in a]
n = len(a)

def ipow(a, n):
	ans = 1
	for i in range(n):
		ans *= a
	return ans
A = ipow(9, n - 1)

def mi(i):
	if i == n - 1:
		return a[i]
	if a[i] == 0:
		return 0
	A = a[i] * mi(i + 1)
	B = (a[i] - 1) * ipow(9, n - (i + 1))
	return max(A, B)
B = mi(0)
print(max(A, B))


from sys import stdin
from math import log10
input = stdin.readline

def get_p(x):
	p = 1
	for x in map(int, str(x)):
		p *= x
	return p
n = int(input())
if log10(n) < 1:
	print(n)
else:
	m = get_p(n)
	for x in range(1, int(log10(n) + 1)):
		d = get_p(n - n % 10 ** x - 1)
		if d > m:
			m = d
	print(m)


def multiply(i):
	s = str(i)
	mu = 1
	for j in s:
		mu *= int(j)
	return mu
ans = []
x = input()
ans.append(multiply(x))
if x[0] == '1':
	ans.append(multiply('9' * (len(x) - 1)))
for i in range(1, len(x) + 1):
	t = str(int(x[0:i]) - 1) + '9' * (len(x) - i)
	ans.append(multiply(t))
print(max(ans))


n = int(input())
number = [i for i in str(n)]
ans = []

def pdt(s):
	ret = 1
	for i in s:
		ret *= int(i)
	return ret
if len(number) == 1:
	print(n)
else:
	ans.append(pdt(number))
	for i in range(len(number)):
		if i == 0 and number[i] == '1':
			tmp = '9' + '9' * len(''.join(number[2:]))
			ans.append(pdt(tmp))
		elif number[i] == '0':
			continue
		else:
			tmp = ''.join(number[:i]) + str(int(number[i]) - 1) + '9' * len(''.join(number[i + 1:]))
			ans.append(pdt(tmp))
	print(max(ans))


import math

def mul(s):
	res = 1
	if s[0] == 0:
		s = s[1:]
	for c in s:
		res *= c
	return res

def max_digits_mul(n):
	s = [int(c) for c in str(n)]
	for i in range(len(s) - 1, -1, -1):
		cur_sum = mul(s[i:])
		prev = [s[i] - 1] + [9] * (len(s) - i - 1)
		if mul(prev) > cur_sum:
			s[i:] = prev
	return mul(s)
n = int(input())
print(max_digits_mul(n))


s = list(input())
n = len(s)

def f(i):
	if i == n:
		return 1
	if int(s[i]) == 0:
		return 0
	if int(s[i]) == 1:
		return max(f(i + 1), 9 ** (n - i - 1))
	return max(f(i + 1) * int(s[i]), (int(s[i]) - 1) * 9 ** (n - i - 1))
print(f(0))


def findProd(nums):
	prod = 1
	for i in nums:
		prod *= i
	return prod

def main():
	nums = list(map(int, input()))
	n = len(nums)
	carry = 0
	ans = 0
	for i in range(n - 1, 0, -1):
		prod1 = findProd(nums)
		if nums[i] != 9:
			nums[i] = 9
			for j in range(i - 1, -1, -1):
				if nums[j] > 0:
					nums[j] -= 1
					break
				else:
					nums[j] = 9
			while nums[0] == 0:
				nums.pop(0)
		prod2 = findProd(nums)
		ans = max(ans, prod1, prod2)
	if n == 1:
		ans = nums[0]
	print(ans)
main()


s = input()
max_p = 1
for i in s:
	max_p *= int(i)
k = s.find('0')
if k == -1:
	k = len(s)
if len(s) == 1:
	print(s)
	exit()
for i in range(k):
	p = 1
	for j in range(len(s)):
		if j < i:
			p *= int(s[j])
		elif j == i:
			if s[j] == '1':
				p *= 1
			else:
				p *= int(s[j]) - 1
		else:
			p *= 9
	max_p = max(p, max_p)
print(max_p)


s = list(str(input()))
lul = 1
lulu = 1
a = 1
l = []
l1 = []
for i in range(1, len(s)):
	if int(s[i - 1]) > 1:
		c = int(s[i - 1]) - 1
		w = 9 ** (len(s) - i)
		lulu = w * c * a
		l1.append(lulu)
	a *= int(s[i - 1])
lulu = 1
for i in range(len(s)):
	lulu *= int(s[i])
l1.append(lulu)
lulu = 1
if s[0] == '1':
	l1.append(9 ** (len(s) - 1))
print(max(l1))


s = input()
n = int(s)
ma = 1
doub_s = s
i = 0
while '0' in s:
	a = int(s[:len(s) - i])
	if a % 10 == 0:
		a -= 1
		s = str(a) + s[len(s) - i:]
	i += 1

def check(s):
	ma = 1
	for i in range(len(s)):
		ma *= int(s[i])
	return ma
ma = check(s)
s = doub_s
for i in range(len(s)):
	try:
		a = int(s[:len(s) - i])
	except:
		a = -1
	while a % 10 != 9 and a > 1:
		a -= 1
		s = str(a) + s[len(s) - i:]
		if ma < check(s):
			ma = check(s)
			break
print(ma)


n = int(input())
if len(str(n)) == 1:
	print(n)
else:
	n1 = n
	n2 = n
	maxi = 0
	mul = 1
	count = 0
	for i in str(n):
		mul *= int(i)
	maxi = max(mul, maxi)
	mul = 1
	sum1 = 0
	while len(str(n1)) > 1:
		r = n1 % 10
		count += 1
		r1 = n % 10 ** count
		sum1 = r1
		n -= sum1 + 1
		if n > 0:
			for i in str(n):
				mul *= int(i)
			maxi = max(mul, maxi)
		mul = 1
		n1 = n1 // 10
	print(maxi)


def product(n):
	z = [int(i) for i in str(n)]
	p = 1
	for i in z:
		p *= i
	return p
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 25, 26, 27, 28, 29, 37, 38, 39, 47, 48, 49, 58, 59, 68, 69, 78, 79, 88, 89, 99, 259, 268, 269, 278, 279, 288, 289, 299, 378, 379, 388, 389, 399, 479, 488, 489, 499, 589, 599, 689, 699, 789, 799, 889, 899, 999, 2599, 2689, 2699, 2789, 2799, 2889, 2899, 2999, 3789, 3799, 3889, 3899, 3999, 4799, 4889, 4899, 4999, 5899, 5999, 6899, 6999, 7899, 7999, 8899, 8999, 9999, 25999, 26899, 26999, 27899, 27999, 28899, 28999, 29999, 37899, 37999, 38899, 38999, 39999, 47999, 48899, 48999, 49999, 58999, 59999, 68999, 69999, 78999, 79999, 88999, 89999, 99999, 259999, 268999, 269999, 278999, 279999, 288999, 289999, 299999, 378999, 379999, 388999, 389999, 399999, 479999, 488999, 489999, 499999, 589999, 599999, 689999, 699999, 789999, 799999, 889999, 899999, 999999, 2599999, 2689999, 2699999, 2789999, 2799999, 2889999, 2899999, 2999999, 3789999, 3799999, 3889999, 3899999, 3999999, 4799999, 4889999, 4899999, 4999999, 5899999, 5999999, 6899999, 6999999, 7899999, 7999999, 8899999, 8999999, 9999999, 25999999, 26899999, 26999999, 27899999, 27999999, 28899999, 28999999, 29999999, 37899999, 37999999, 38899999, 38999999, 39999999, 47999999, 48899999, 48999999, 49999999, 58999999, 59999999, 68999999, 69999999, 78999999, 79999999, 88999999, 89999999, 99999999, 259999999, 268999999, 269999999, 278999999, 279999999, 288999999, 289999999, 299999999, 378999999, 379999999, 388999999, 389999999, 399999999, 479999999, 488999999, 489999999, 499999999, 589999999, 599999999, 689999999, 699999999, 789999999, 799999999, 889999999, 899999999, 999999999, 2 * 10 ** 9 + 1]
n = int(input())
for i in range(len(a)):
	if a[i] > n:
		print(product(a[i - 1]))
		exit()


def f(x):
	if x == 0:
		return 1
	elif x < 10:
		return x
	else:
		return max(x % 10 * f(x // 10), 9 * f(x // 10 - 1))
print(f(int(input())))


s = input()
mx = 1
for x in s:
	mx *= int(x)
for i in range(1, len(s) + 1):
	s1 = s[:i]
	n = int(s1) - 1
	if n == 0:
		s1 = ''
	else:
		s1 = str(n)
	s1 += '9' * (len(s) - i)
	res = 1
	for x in s1:
		res *= int(x)
	mx = max(res, mx)
print(mx)


n = input()
intn = list(map(int, list(n)))
pro = []
if int(n) > 9:
	for i in range(0, len(n) - 1):
		ss = ''
		tt = ''.join((v for v in n[0:i + 1]))
		t = int(tt) - 1
		ss += str(t) + '9' * (len(n) - i - 1)
		pro.append(ss)
	pro.append(n)
else:
	pro.append(n)
ans = []
for j in pro:
	anss = 1
	for k in j:
		if j.index(k) == 0 and k == '0':
			pass
		else:
			anss *= int(k)
	ans.append(anss)
print(max(ans))


n = int(input())
l = len(str(n))
p = 1
for i in range(l):
	curp = 1
	if n > 0:
		for k in str(n):
			curp *= int(k)
	p = max(p, curp)
	if n >= 10 ** i:
		n -= (int(str(n)[len(str(n)) - 1 - i]) + 1) * 10 ** i
print(p)


n = list(input())
ans = 0
tc = 1
for i in range(len(n)):
	j = int(n[i])
	t2 = (j - 1) * tc
	tc = j * tc
	ans = max(t2 * 9 ** (len(n) - i - 1), ans)
	if i == 0 and t2 == 0:
		ans = max(9 ** (len(n) - i - 1), ans)
ans = max(ans, tc)
print(ans)


def foo(nums):
	res = 1
	flag = 0
	for i in range(len(nums)):
		if nums[i] != 0:
			flag = 1
		if flag:
			res *= nums[i]
	return res
nums = list(map(int, list(input())))
res = foo(nums)
for i in range(len(nums)):
	nums2 = nums[:i]
	if nums[i] != 0:
		nums2.append(nums[i] - 1)
		for j in range(len(nums) - i - 1):
			nums2.append(9)
		res = max(res, foo(nums2))
print(res)


n = int(input())
if n <= 9:
	print(n)
else:
	p1 = 1
	for i in str(n):
		p1 = p1 * int(i)
	n2 = str(n)
	p3 = 1
	for i in range(1, len(str(n2))):
		n1 = n
		p2 = 1
		d = int(n) % 10 ** i + 1
		n1 = int(n1) - d
		for j in str(n1):
			p2 = p2 * int(j)
		if p2 > p3:
			p3 = p2
	print(max(p1, p2, p3))


from collections import defaultdict
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
n = list(input())
c = 0
t = 1
for i in range(len(n)):
	j = int(n[i])
	t2 = t * (j - 1)
	t = t * j
	c = max(t2 * 9 ** (len(n) - i - 1), c)
	if i == 0 and t2 == 0:
		c = max(9 ** (len(n) - i - 1), c)
c = max(t, c)
print(c)


a = list(input())
ans = 1
for y in a:
	ans = ans * int(y)
x = 0
n = len(a)
for x in range(n):
	if a[x] != '0':
		tempans = int(a[x]) - 1
		for xx in range(x):
			tempans = tempans * int(a[xx])
		if tempans == 0:
			tempans = 1
		ans = max(ans, tempans * 9 ** (n - x - 1))
print(ans)


s = input()
if len(s) == 1:
	print(s)
	exit()
ans = 1
for i in range(len(s)):
	ans *= int(s[i])
for i in range(max(len(s), 2)):
	if s[i] == '0':
		continue
	p = int(s[i]) - 1
	if p == 0:
		p = 1
	for j in range(len(s)):
		if i == j:
			continue
		if j < i:
			p *= int(s[j])
		else:
			p *= 9
	else:
		ans = max(ans, p)
else:
	print(ans)


n = int(input())

def p(x):
	ans = 1
	while x > 0:
		ans *= x % 10
		x //= 10
	return ans
ans = p(n)
for i in range(len(str(n))):
	cans = 9 ** i * p(n // 10 ** i - 1)
	ans = max(ans, cans)
print(ans)


n = int(input())

def get_p(n):
	if n == 0:
		return 0
	p = 1
	while n > 0:
		p *= n % 10
		n //= 10
	return p
mx = get_p(n)
d = 10
nn = n
while d <= n:
	nn -= d
	nn = nn - nn % d + (d - 1)
	mx = max(get_p(nn), mx)
	d *= 10
print(mx)


def pr(x):
	ans = 1
	length = len(x)
	for i in range(length):
		ans *= x[i]
	return ans
n = list(map(int, input()))
if len(n) == 1:
	print(n[0])
	exit()
elif len(n) > 1 and n[0] == 1:
	print(9 ** (len(n) - 1))
	exit()
m = n.copy()
for i in range(len(n) - 1, 0, -1):
	if n[i - 1] == 0:
		continue
	elif pr([n[i - 1] - 1, 9]) > pr(n[i - 1:i + 1]) or n[i - 1] == 1:
		n[i - 1] -= 1
		n[i] = 9
init = n[0] - 1
t = []
for p in range(len(n)):
	if n[p] < m[p]:
		t = n[:p + 1] + [9 for _ in range(len(n) - p - 1)]
		break
print(max(pr(n), pr([init] + [9 for k in range(len(n) - 1)]), pr(t)))


def evalu(dig):
	if dig[0] == 0:
		return 0
	if len(dig) == 1:
		return dig[0]
	return max(dig[0] * evalu(dig[1:]), max(1, dig[0] - 1) * 9 ** (len(dig) - 1))
n = str(int(input()))
dig = list(n)
for i in range(len(dig)):
	dig[i] = int(dig[i])
print(evalu(dig))


def mult(a):
	if int(a) <= 9:
		return int(a)
	m = 1
	for i in range(len(a)):
		m *= int(a[i])
	return m
a = input()
mx = mult(a)
for i in range(1, len(a)):
	mx = max(mx, mult(str(int(a) - int(a[len(a) - i:len(a)]) - 1)))
print(mx)


def sd(a):
	sm = 0
	while a:
		sm = sm + a % 10
		a = a // 10
	return sm

def pro(n):
	pro = 1
	while n > 0:
		pro *= n % 10
		n = n // 10
	return pro

def findpro(x):
	b = 1
	ans = x
	while x != 0:
		cur = (x - 1) * b + (b - 1)
		if pro(cur) > pro(ans) or (pro(cur) == pro(ans) and cur > ans):
			ans = cur
		x = x // 10
		b = b * 10
	return ans
n = int(input())
print(pro(findpro(n)))


def product(n: str) -> int:
	a = 1
	for i in n:
		a *= int(i)
	return a

def bruteforce(n):
	maxval = 0
	maxind = 0
	for i in range(n + 1):
		value = product(str(i))
		if value >= maxval:
			maxval = value
			maxind = i
	return maxval
	print('value:', maxval, '| index:', maxind)

def fast(n):
	orig_str = str(n)
	if orig_str[0] == '1':
		return 9 ** (len(orig_str) - 1)
	new_str = ''
	for i in range(len(orig_str) - 1, -1, -1):
		if orig_str[i] == '0':
			new_str = '9' + new_str
		elif i + 1 < len(orig_str) and orig_str[i + 1] == '0':
			new_str = str(int(orig_str[i]) - 1) + '9' * (len(orig_str) - i - 1)
		else:
			new_str = orig_str[i] + new_str
	if new_str[0] == '0':
		new_str = new_str[1:]
	maxval = product(new_str)
	for i in range(len(orig_str) - 1, 0, -1):
		if new_str[i] != '9':
			new_str = new_str[:i - 1] + str(int(new_str[i - 1]) - 1) + '9' + new_str[i + 1:]
		temp = product(new_str)
		if temp > maxval:
			maxval = temp
	return maxval
print(fast(int(input())))


def to_arr(s):
	a = [0] * len(s)
	for i in range(len(s)):
		a[i] = int(s[i])
	return a
s = to_arr(input())
n = len(s)
ans = 1
for i in range(n):
	ans *= s[i]
for k in range(n):
	if s[k] == 0:
		continue
	a = s[:]
	a[k] -= 1
	for i in range(k + 1, n):
		a[i] = 9
	p = 1
	st = 0
	for i in range(n):
		if a[i]:
			st = i
			break
	for i in range(st, n):
		p *= a[i]
	ans = max(p, ans)
print(ans)


def f(n):
	if n < 10:
		return n
	else:
		s = list(str(n))
		s = list(map(int, s))
		q = max(1, s[0] - 1) * 9 ** (len(s) - 1)
		w = s[0] * f(n % 10 ** (len(s) - 1))
		return max(q, w)
print(f(int(input())))


n = int(input())
m = 0
if n < 10000:
	for i in range(1, n + 1):
		x = i
		s = 1
		while x != 0:
			a = x % 10
			s *= a
			x //= 10
		if s > m:
			m = s
else:
	x = n - n % 10 ** (len(str(n)) - 1) - 1
	s = 1
	while x != 0:
		a = x % 10
		s *= a
		x //= 10
	if s > m:
		m = s
	for i in range(1, len(str(n))):
		x = n - 1 - n % 10 ** i
		s = 1
		while x != 0:
			a = x % 10
			s *= a
			x //= 10
		if s > m:
			m = s
	for i in range(n - 20000, n + 1):
		x = i
		s = 1
		while x != 0:
			a = x % 10
			s *= a
			x //= 10
		if s > m:
			m = s
print(m)


def fun1(n):
	if str(n).count('0') == len(str(n)) - 1 and len(str(n)) != 1:
		n -= 1
	n = list(str(n))
	idx = len(n) - 1
	mx = 0
	last = False
	while idx != -1:
		if last:
			if idx == 0 and n[idx] == '1':
				n = n[1:]
			else:
				n[idx] = str(int(n[idx]) - 1)
				if n[idx] == '-1':
					n[idx] = '9'
					idx -= 1
					last = True
					continue
		if '0' not in n and '-1' not in n:
			prod = 1
			for i in n:
				prod *= int(i)
			mx = max(mx, prod)
		if n[idx] == '9':
			idx -= 1
			last = False
		else:
			n[idx] = '9'
			idx -= 1
			last = True
	return mx
print(fun1(int(input())))


import sys
num = sys.stdin.readline().rstrip()

def pr(n):
	if n < 0:
		return 0
	a = 1
	for i in range(0, len(list(str(n)))):
		a *= int(list(str(n))[i])
	return a

def findProduct(n, a, l):
	if n < 0:
		nna = [pr(i) for i in a]
		return max(nna)
	i = 0
	na = a
	while (n - 10 ** l * i + 1) % 10 ** (l + 1) != 0:
		na.append(n - 10 ** l * i)
		i += 1
	return findProduct(n - 10 ** l * i, na, l + 1)
print(findProduct(int(num), [], 0))


a = [int(i) for i in input()]
z = 1
ans = 9 ** (len(a) - 1)
for (i, x) in enumerate(a):
	ans = max(ans, (x - 1) * z * 9 ** (len(a) - i - 1))
	z *= x
print(max(ans, z))


n = int(input())
n += 1
n = str(n)[::-1]
res = 0
for i in range(len(n)):
	if n[i] == '0':
		continue
	v = '9' * i + chr(ord(n[i]) - 1) + n[i + 1:]
	v = int(v[::-1])
	cnd = 1
	for c in str(v):
		cnd *= int(c)
	res = max(res, cnd)
print(res)


n_str = input()
possible_numbers = [n_str]
for i in reversed(range(1, len(n_str))):
	head = str(int(n_str[:i]) - 1)
	if head == '0':
		head = ''
	possible_numbers.append(head + '9' * (len(n_str) - i))
max_prod = 0
max = ''
for v in possible_numbers:
	prod = 1
	for d in v:
		prod *= int(d)
	if prod > max_prod:
		max_prod = prod
		max = v
print(max_prod)


def calc(n):
	ret = 1
	while n != 0:
		ret *= n % 10
		n //= 10
	return ret

def solve():
	n = int(input())
	ans = calc(n)
	for i in range(1, 10):
		a = (n + 1) % 10 ** i
		if n < a:
			break
		ans = max(ans, calc(n - a))
	return ans
print(solve())


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = li3()
ans = 1
curr1 = 1
le = len(n)
for i in range(len(n)):
	curr1 *= n[i]
	temp = 1
	for j in range(i + 1, le):
		temp *= n[j]
	ans = max(ans, curr1 * temp)
	curr1 //= n[i]
	ans = max(ans, curr1 * max(1, n[i] - 1) * 9 ** (le - i - 1))
	if i < le - 1 and n[i + 1] == 0:
		break
	else:
		curr1 *= n[i]
print(ans)


import sys, math, io, os, time, itertools, collections
mod = 10 ** 9 + 7
sys.setrecursionlimit(10000)
p = sys.stdout.write
i = sys.stdin.readline
global start, end

def digprod(n):
	prod = 1
	while n:
		prod *= n % 10
		n = n // 10
	return prod

def main():
	n = int(i())
	big = 0
	prod = 1
	while n > 0:
		if n % 10 == 9:
			prod *= 9
			n = n // 10
		big = max(big, prod * digprod(n))
		n -= 1
	p(str(big) + '\n')
t = 1
start = time.perf_counter()
for _ in range(t):
	main()
end = time.perf_counter()


def prd(s):
	acc = 1
	for c in s:
		acc *= int(c)
	return acc
ns = input()
n = int(ns)
if n < 10:
	print(n)
	exit()
ans = max(prd(ns), 9 ** (len(ns) - 1))
for i in range(len(ns)):
	if ns[i] == '0':
		continue
	ans = max(ans, prd(ns[:i] + chr(ord(ns[i]) - 1)) * 9 ** (len(ns) - i - 1))
print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))

def fun(n):
	x = str(n)
	an = 9 ** (len(x) - 1) * (int(x[0]) - 1 if x[0] != '1' else 1)
	if n < 10:
		return n
	elif x[0] == '1' or int(x[0]) * int(x[1]) <= 9 * (int(x[0]) - 1):
		return an
	else:
		a = int(x[0]) * (int(x[1]) - 1) * 9 ** (len(x) - 2)
		b = 1
		k = f = 1
		for i in x:
			b *= int(i)
		c = 1
		for i in x:
			if i != '9' and k == 0:
				c *= 9
				continue
			c *= int(i)
			if i == '9' and k:
				k = 0
		c //= 9
		c *= 8
		return max([an, a, b, c])
(n,) = I()
print(fun(n))


n = input()
l = len(n)

def pr(s):
	p = 1
	for i in s:
		p *= int(i)
	return p
arr = [pr(n)]
pref = ''
wed = True
while len(pref) < len(n):
	if wed == True and n[len(pref)] == '1':
		arr.append(pr('9' * (len(n) - 1)))
		wed = False
	else:
		wed = False
		if n[len(pref)] == '0' or n[len(pref)] == '1':
			pref += n[len(pref)]
			continue
		arr.append(pr(pref + str(int(n[len(pref)]) - 1) + '9' * (len(n) - len(pref) - 1)))
	pref += n[len(pref)]
print(max(arr))


n = input()
n = list(map(int, list(n)))
possible = [n.copy()]
for i in range(len(n) - 1, 0, -1):
	n[i] = 9
	n[i - 1] -= 1
	for j in range(i - 1, 0, -1):
		if n[j] == -1:
			n[j] = 9
			n[j - 1] -= 1
	if n[0] != -1:
		possible.append(n.copy())
for i in possible:
	for (j, x) in enumerate(i):
		if x == 0:
			i[j] = 1
		else:
			continue
for (i, x) in enumerate(possible):
	possible[i] = ''.join(map(str, x))
	res = 1
	for j in possible[i]:
		res *= int(j)
	possible[i] = res
print(max(possible))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = input()
l = list(n)
l1 = []
if len(n) == 1:
	print(n)
else:
	for j in range(len(n) - 1):
		x = n[j:j + 2]
		if max(1, int(x[0]) - 1) * 9 > int(x[0]) * int(x[1]):
			l[j] = str(max(1, int(l[j]) - 1))
			l[j + 1] = '9'
			break
		else:
			s = ''.join(l[:j]) + str(int(l[j]) - 1) + '9' * (len(n) - j - 1)
			l1.append(s)
	k = j + 2
	for j in range(k, len(n)):
		l[j] = '9'
	ans = 1
	for j in l:
		ans *= int(j)
	for j in l1:
		an = 1
		for k in j:
			if k != '0':
				an *= int(k)
		ans = max(ans, an)
	print(ans)


n = input()
mx = 1
for i in range(len(n)):
	mx *= int(n[i])
mx = max(mx, 9 ** (len(n) - 1))
for i in range(len(n)):
	ans = 1
	for j in range(0, i):
		ans *= int(n[j])
	ans *= int(n[i]) - 1
	ans *= 9 ** (len(n) - i - 1)
	mx = max(mx, ans)
print(mx)


def st(i):
	return list(map(int, str(i)))

def into(ls):
	return int(''.join([str(i) for i in ls]))

def pro(ls):
	v = 1
	for x in ls:
		v *= x
	return v
kk = lambda : map(int, input().split())
k2 = lambda : map(lambda x: int(x) - 1, input().split())
ll = lambda : list(kk())
ls = list(map(int, list(input())))
loc = maxv = 0
maxv = pro(ls)
for i in range(len(ls) - 1, -1, -1):
	loc += 1
	if ls[i] != 9:
		ls[i] = 9
		ls = st(max(into(ls) - 10 ** loc, 0))
	maxv = max(maxv, pro(ls))
print(maxv)


from functools import reduce
digits = [int(i) for i in input()]
product = reduce(lambda x, y: x * y, digits)
max_p = product
power = 1
number = int(''.join((str(d) for d in digits)))
while power < len(digits):
	substract = number % 10 ** power + 1
	number -= substract
	digits = [int(i) for i in str(number)]
	product = reduce(lambda x, y: x * y, digits)
	max_p = product if product > max_p else max_p
	power += 1
print(max_p)


import sys
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())

def getDigitMul(ns):
	mul = 1
	for i in list(ns):
		mul *= int(i)
	if mul == 0:
		return 1
	return mul

def getMax(n):
	maxMul = 0
	for i in range(n, max(0, n - 10 ** 5), -1):
		maxMul = max(maxMul, getDigitMul(str(i)))
	return maxMul
ns = str(n)
endlen = len(ns) - 1
ans = getDigitMul(ns)
for i in range(1, len(ns)):
	ans = max(ans, getDigitMul(str(int(ns[0:i]) - 1)) * 9 ** endlen)
	endlen -= 1
print(ans)


def solve(n):
	st = str(n)
	if len(st) == 1:
		return n
	if int(st[0]) == 1:
		return 9 ** (len(st) - 1)
	else:
		x = (int(st[0]) - 1) * 9 ** (len(st) - 1)
		y = int(st[0]) * solve(int(st[1:]))
		return max(x, y)
n = int(input())
print(solve(n))


def solve(s):
	if len(str(s)) == 1:
		return s
	ans1 = solve(s // 10)
	ans2 = solve(s // 10 - 1)
	return max(ans1 * (s % 10), ans2 * 9, 9)
n = int(input())
print(solve(n))


def product(p):
	f = 1
	while p:
		f *= p % 10
		p //= 10
	return f
n = int(input())
p = len(str(n)) - 1
arr = []
while p >= 0:
	arr.append(product(n - n % 10 ** p - 1))
	p -= 1
arr.append(product(n))
print(max(arr))


n = input()

def get_product(n):
	if len(n) == 1:
		return int(n)
	f_digit = int(n[0])
	prod = 9 ** (len(n) - 1)
	if f_digit != 1:
		prod *= f_digit - 1
	return max(prod, f_digit * get_product(n[1:]))
print(get_product(n))


s = input()
length = len(s)
(n, string, result) = (int(s), '', 1)
for (i, x) in enumerate(s):
	result *= int(x)
for i in range(length - 1, 0, -1):
	string = s[i] + string
	numeric = n - 1 - int(string)
	res = 1
	for (i, x) in enumerate(str(numeric)):
		res *= int(x)
	result = max(result, res)
print(result)


l = list((int(c) for c in str(int(input()))))

def prod(l):
	p = 1
	for d in l:
		p *= max(d, 1)
	return p
m = prod(l)
i = len(l) - 1
while i >= 0:
	while i >= 0 and l[i] == 9:
		i -= 1
	if i < 0:
		break
	l[i] = 9
	while i > 0 and l[i - 1] == 0:
		l[i - 1] = 9
		i -= 1
	i -= 1
	if i < 0:
		break
	l[i] = l[i] - 1
	m = max(m, prod(l))
print(m)


def solution(n):
	if n < 10:
		return max(1, n)
	return max(solution(n // 10) * (n % 10), solution(n // 10 - 1) * 9)
n = int(input())
print(solution(n))


def solve(n, i, yo, le):
	z = 0
	if n != '0':
		k = str(int(n) - 1)
		z = yo + k + (le - i) * '9'
	return int(z)

def mul(n):
	boo = 1
	for i in str(n):
		boo *= int(i)
	return boo
n = int(input())
ba = 1
ma = 1
s = str(n)
da = 1
if len(s) == 1:
	print(n)
else:
	maxi = mul(n)
	for i in range(len(s)):
		k = solve(s[i], i + 1, s[:i], len(s))
		maxi = max(maxi, mul(k))
	print(maxi)


from sys import exit
n = int(input())

def mult(n):
	res = 1
	for ch in str(n):
		res *= int(ch)
	return res
if len(str(n)) == 1:
	print(n)
	exit()
s_n = str(n)
new_n = [n]
for i in range(1, len(s_n)):
	new_n.append(n - (n % 10 ** i + 1))
maxim = max(map(mult, new_n))
print(maxim)


s = list((ord(x) - ord('0') for x in input()))
trace = [0] * len(s)
result = 0

def check():
	global result
	i = 0
	if trace[0] == 0:
		i = 1
	tmp = 1
	for k in range(i, len(s)):
		tmp *= trace[k]
	result = max(result, tmp)
	pass

def dfs(i):
	if i == len(s):
		check()
	elif s[i] != 0:
		trace[i] = s[i]
		dfs(i + 1)
		trace[i] = s[i] - 1
		for j in range(i + 1, len(s)):
			trace[j] = 9
		check()
dfs(0)
print(result)


gi = lambda : list(map(int, input().strip().split()))

def p(m):
	ans = 1
	for e in m:
		ans *= int(e)
	return ans

def f(m):
	if m == '':
		return 1
	if len(m) == 1:
		return int(m)
	if int(m[0]) == 1:
		return f('9' * (len(m) - 1))
	if m[0] == '0':
		return f(m[1:])
	return max(p(str(int(m[0]) - 1) + '9' * (len(m) - 1)), int(m[0]) * f(m[1:]))
(n,) = gi()
if n < 10:
	print(n)
	exit()
s = str(n)
print(f(s))


def multiplyList(myList):
	result = 1
	for x in myList:
		result = result * x
	return result
n = int(input())
num = list(map(int, str(n)))
val = multiplyList(num)
max = 0
s = 0
p = 1
for _ in range(len(num) - 1):
	s = s * 10 + 1
	p = p * 10
	tst = n - n % p - 1 * p
	tst += s * 9
	num = list(map(int, str(tst)))
	valv = multiplyList(num)
	if max < valv:
		max = valv
print(max) if max >= val else print(val)


n = int(input())
p = n
a = []
c = []
while n:
	t = n % 10
	a.append(t)
	n = n // 10
a = a[::-1]
s = 1
for i in range(len(a)):
	s = 1
	for j in range(i + 1):
		if j != i:
			s = s * a[j]
		elif a[j] != 1 and a[j] != 0:
			s = s * (a[j] - 1)
		else:
			pass
	s = s * 9 ** (len(a) - i - 1)
	c.append(s)
s = 1
for i in range(len(a)):
	s = s * a[i]
c.append(s)
print(max(c))


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

def f(s):
	if len(s) == 1:
		return int(s)
	elif s[0] == '1':
		return 9 ** (len(s) - 1)
	else:
		v1 = int(s[0]) * f(s[1:])
		v2 = (int(s[0]) - 1) * 9 ** (len(s) - 1)
		return max(v1, v2)

def main():
	s = input()
	ans = f(s)
	print(ans)
main()


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	s = si()
	x = []
	for i in s:
		x.append(int(i))
	n = len(x)
	ans = []
	ans1 = 1
	for i in range(n - 1):
		if x[i] == 0:
			continue
		p = ans1
		if x[i] != 1:
			p *= x[i] - 1
		p *= pow(9, n - i - 1)
		ans.append(p)
		ans1 *= x[i]
	ans.append(ans1 * x[n - 1])
	print(max(ans))
solve()


def multy(a):
	summa = 1
	i = 0
	while a % 10 ** i != a:
		summa *= a % 10 ** (i + 1) // 10 ** i
		i += 1
	return summa

def f(a):
	b = 0
	for i in range(len(a)):
		b += a[i] * 10 ** (len(a) - i - 1)
	return b
n = input()
chislo = int(n)
c = []
iter = len(n) - 1
for i in range(len(n)):
	c.append(int(n[i]))
mas = []

def rec(a, i, t):
	mas.append(f(a))
	if i > 0:
		if a[i] == 9:
			t = 0
		else:
			a[i] = 9
			t = 1
		a[i - 1] -= t
		rec(a, i - 1, 0)
if chislo < 10:
	print(chislo)
else:
	rec(c, iter, 0)
	for i in range(len(mas)):
		mas[i] = multy(mas[i])
	print(max(mas))


def nirvMax(number):
	if number == 0:
		return 1
	if number < 10:
		return number
	figual = nirvMax(number // 10) * (number % 10)
	fnove = nirvMax(number // 10 - 1) * 9
	if figual > fnove:
		return figual
	else:
		return fnove
number = int(input())
print(nirvMax(number))


N = int(input())

def digit_product(digits):
	product = 1
	for digit in digits:
		product *= digit
	return product
digits = []
while N > 0:
	digits.append(N % 10)
	N //= 10
max_product = digit_product(digits)
cur_index = 0
while cur_index < len(digits) - 1:
	while digits[cur_index] == 9 and cur_index < len(digits) - 1:
		cur_index += 1
	if digits[cur_index] > 0 and cur_index < len(digits) - 1:
		digits[cur_index] = 9
		cur_index += 1
		digits[cur_index] -= 1
	while digits[cur_index] <= 0 and cur_index < len(digits) - 1:
		digits[cur_index] = 9
		cur_index += 1
		digits[cur_index] -= 1
	if cur_index == len(digits) - 1 and digits[cur_index] == 0:
		del digits[-1]
	product = digit_product(digits)
	max_product = max(max_product, product)
print(max_product)


def cal(k):
	if k == 0:
		return 1
	if k < 10:
		return k
	return max(cal(k // 10) * (k % 10), cal(k // 10 - 1) * 9)

def main():
	answer = input()
	answer = int(answer)
	print(cal(answer))
main()


def multDigitos(a):
	for y in list(a):
		r = 1
		for y in list(a):
			r *= int(y)
	return r
x = input()
resultados = []
resultados.append(multDigitos(x))
if len(x) > 1:
	for i in range(1, len(x)):
		vira9 = str(int(x[0:i]) - 1) + '9' * (len(x) - i)
		if vira9[0] == '0':
			vira9 = vira9[1:]
		resultados.append(multDigitos(vira9))
print(max(resultados))


def multiply(s):
	cnt = 1
	for i in s:
		cnt *= int(i)
	return cnt
s = input()
prod = []
for k in range(len(s)):
	if int(s[k]) != 0:
		prod.append(s[:k] + str(int(s[k]) - 1) + '9' * (len(s) - k - 1))
prod.append(s)
prod = [multiply(str(int(i))) for i in prod]
print(max(prod))


def product(x):
	prod = 1
	while x:
		prod *= x % 10
		x //= 10
	return prod
n = input()
num1 = 0
for i in range(len(n)):
	num1 = num1 * 10 + ord(n[i]) - 48
ans = product(num1)
for i in range(len(n)):
	if n[i] == '0':
		continue
	curr = list(n)
	curr[i] = chr(ord(curr[i]) - 1)
	for j in range(i + 1, len(curr)):
		curr[j] = '9'
	num = 0
	for j in range(len(curr)):
		num = num * 10 + ord(curr[j]) - 48
	ans1 = product(num)
	if ans1 > ans:
		ans = ans1
print(ans)


n = int(input())
ans = 1
e = n
cou = 0
while e > 0:
	cou += 1
	e //= 10
dp = [0] * cou
dp[0] = n % 10
n //= 10
c = 1
for i in range(1, cou):
	dp[i] = max(dp[i - 1] * (n % 10), max(1, n % 10 - 1) * 9 ** c)
	c += 1
	n //= 10
print(dp[n - 1])


def pro(a, l):
	if l == 1:
		return int(a)
	return max(max(int(a[0]) - 1, 1) * 9 ** (l - 1), int(a[0]) * pro(a[1:], l - 1))
a = input()
print(pro(a, len(a)))


n = int(input())
d = len(str(n))
r = d - 1

def prod(a):
	p = 1
	for j in range(len(str(a))):
		p *= int(str(a)[j])
	return p
mx = 0
des = 1
for i in range(-1, -d - 1, -1):
	mx = max(mx, prod(n))
	if r != 0:
		n -= (int(str(n)[i]) + 1) * des
	des *= 10
	r -= 1
	if n <= 0:
		break
print(mx)


def compute(arr):
	n = len(arr)
	m = mul(arr)
	if n == 1:
		return m
	for i in range(n - 1):
		sub = []
		if arr[i] == 0:
			continue
		for j in range(i):
			sub.append(arr[j])
		sub.append(arr[i] - 1)
		for j in range(i + 1, n):
			sub.append(9)
		val = mul(sub)
		m = max(val, m)
	return m

def mul(arr):
	val = 1
	start = 0
	if arr[0] == 0:
		start = 1
	for i in range(start, len(arr)):
		val = val * arr[i]
	return val

def convert(arr):
	n = len(arr)
	out = 0
	for i in range(n):
		out = out + 10 ** (n - 1 - i)

def main():
	val = input()
	n = len(val)
	arr = [int(val[i]) for i in range(n)]
	print(compute(arr))
main()


s = input()
ans = int(s[0])
if s[0] == '1':
	if len(s) != 1:
		ans = 9 ** (len(s) - 1)
		wajdi = 1
	else:
		ans = 1
	print(ans)
else:
	wajdi = int(s[0])
	if len(s) > 1:
		ans = (wajdi - 1) * 9 ** (len(s) - 1)
	else:
		ans = wajdi
	from math import *
	for i in range(1, len(s)):
		mx = s[i]
		c = int(mx)
		if i < len(s) - 1:
			c -= 1
		if mx == '1' or mx == '0':
			break
		ans = max(ans, wajdi * c * 9 ** (len(s) - 1 - i))
		wajdi *= int(mx)
	print(ans)


def proc(x):
	y = [int(i) for i in str(x)]
	p = 1
	for i in y:
		p *= i
	return p

def transf(x):
	a = [str(i) for i in x]
	return int(''.join(a))

def solver(v):
	pilha = [int(i) for i in str(v)]
	maior = proc(transf(pilha))
	tam = len(pilha)
	pilha = pilha[:-1]
	while pilha != []:
		if pilha[-1] == 0:
			pilha = pilha[:-1]
		else:
			pilha[-1] -= 1
			d = str(transf(pilha))
			over = tam - len(d)
			d = d + '9' * over
			d = int(d)
			maior = max(maior, proc(d))
	return maior
n = int(input())
print(solver(n))


def solve(x, f=False):
	if len(x) == 1:
		return int(x)
	first = int(x[0])
	remainder = x[1:]
	len_rem = len(remainder)
	nines = 9 ** len_rem
	sub_one = first - 1
	if f and sub_one == 0:
		sub_one = 1
	return max(first * solve(remainder), sub_one * nines)
n = input()
print(solve(n, True))


def pod(n):
	ans = 1
	while n > 0:
		ans *= n % 10
		n = n // 10
	return ans
n = input()
ans = (len(n) - 1) * 9
ans = max(ans, pod(int(n)))
sz = len(n)
for i in range(1, sz):
	ind = sz - i
	num = n[:ind] + '9' * (sz - ind)
	if int(num) > int(n):
		if num[ind - 1] == '0':
			num = num[:ind - 1] + '9' + num[ind:]
		else:
			num = num[:ind - 1] + str(int(num[ind - 1]) - 1) + num[ind:]
	if int(num) <= int(n):
		ans = max(ans, pod(int(num)))
print(ans)


from math import log10
n = int(input())

def prod(a):
	P = 1
	for i in str(a):
		P *= int(i)
	return P
power = int(log10(n))
Ans = prod(n)
while power >= 0:
	k = (n // 10 ** power - 1) * 10 ** power + (10 ** power - 1)
	power -= 1
	Ans = max(Ans, prod(k))
print(Ans)


def dfs(nd, i):
	if i == len(nd):
		return 1
	c0 = nd[i]
	c1 = nd[i] - 1
	if c1 == 0:
		c1 = 1
	return max(c0 * dfs(nd, i + 1), c1 * 9 ** (len(nd) - i - 1))

def main():
	n = int(input())
	nd = []
	while n > 0:
		nd = [n % 10] + nd
		n //= 10
	ans = dfs(nd, 0)
	print(ans)
exit(main())


n = int(input())
ans = 1

def f(m):
	r = 1
	while m:
		r *= m % 10
		m //= 10
	return r

def dfs(m):
	r = f(m)
	if m >= 9:
		r = max(r, 9 * dfs((m - 9) // 10))
	return r
print(dfs(n))


def pro(a):
	pr = 1
	for i in range(len(a)):
		pr *= a[i]
	return pr
st = input()
n = int(st)
a = [int(s) for s in list(st)]
prm = pro(a)
pr = 0
if a[0] == 1:
	prm = max(9 ** (len(a) - 1), prm)
for i in range(1, len(a)):
	if a[-i - 1] != 0:
		pr = pro(a[:-i - 1]) * 9 ** i * (a[-i - 1] - 1)
	else:
		pass
	if pr > prm:
		prm = pr
print(prm)


n = int(input())
digits = []
while n:
	digits.append(n % 10)
	n //= 10

def count(digits):
	i = len(digits) - 1
	res = 1
	while i >= 0:
		if digits[i] == 0:
			break
		res *= digits[i]
		i -= 1
	return res
digits = digits[::-1]
m = count(digits)
for i in range(len(digits) - 1, 0, -1):
	if digits[i] == 9:
		continue
	digits[i] = 9
	j = i - 1
	while digits[j] == 0:
		digits[j] = 9
		j -= 1
	digits[j] -= 1
	m = max(count(digits), m)
print(m)


def obter_produto(n):
	prod = 1
	for i in n:
		prod *= i
	return prod

def contem_zero(n):
	for i in n:
		if i == 0:
			return True
	return False

def acha_zero(n):
	for i in range(len(n))[::-1]:
		if n[i] == 0:
			return i
	return -1

def copy_list(l1):
	l2 = []
	for i in l1:
		l2.append(i)
	return l2
n = list(str(int(input())))
n.reverse()
for i in range(len(n)):
	n[i] = int(n[i])
if contem_zero(n):
	pos_zero = acha_zero(n)
	n[pos_zero + 1] -= 1
	for i in range(pos_zero + 1):
		n[i] = 9
	if n[-1] == 0:
		del n[-1]
prod = obter_produto(n)
n2 = copy_list(n)
n_final = copy_list(n)
for i in range(1, len(n)):
	n2[i] -= 1
	n2[i - 1] = 9
	if n2[-1] == 0:
		del n2[-1]
	prod2 = obter_produto(n2)
	if prod2 > prod:
		prod = prod2
		n_final = copy_list(n2)
n_final.reverse()
print(prod)


n = input()
length = len(n)

def get_product(s):
	(prod, temp) = (1, list(s))
	if s[0] == '0':
		temp = s[1:]
	for i in temp:
		prod *= int(i)
	return prod
if length == 1:
	print(n)
else:
	maxi = get_product(n)
	for i in range(1, length + 1):
		temp = str(int(n[:i]) - 1) + '9' * (length - i)
		check = get_product(temp)
		if check > maxi:
			maxi = check
	print(maxi)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
ans = 1
e = n
cou = 0
while e > 0:
	cou += 1
	e //= 10
dp = [0] * cou
dp[0] = n % 10
n //= 10
c = 1
for i in range(1, cou):
	dp[i] = max(dp[i - 1] * (n % 10), max(1, n % 10 - 1) * 9 ** c)
	c += 1
	n //= 10
print(dp[n - 1])


import operator
from functools import reduce

def prod(d):
	return reduce(operator.mul, d, 1)
n = int(input())
num = n
digits = []
while num > 0:
	digits.append(num % 10)
	num = num // 10
length = len(digits)
ans = prod(digits)
current = 1
while current < length:
	if digits[current] > 0:
		digits[current] -= 1
		for i in range(current):
			digits[i] = 9
		ans = max(ans, prod(digits[:current if digits[current] == 0 else length]))
	current += 1
print(ans)


no = input()
integer = int(no)

def mul(x):
	h = 1
	while x // 10 > 0:
		h *= x % 10
		x = x // 10
	return h * x
ans = mul(integer)
for i in range(len(no) - 1, 0, -1):
	temp = int(no[i])
	if temp != 9:
		integer = integer - 10 ** (len(no) - i - 1) * (temp + 1)
		no = str(integer)
		ans = max(ans, mul(integer))
print(ans)


def prd(n):
	t = 1
	p = n
	while p > 0:
		t = t * (p % 10)
		p = p // 10
	return t
n = int(input())
b = 1
ans = n
while n != 0:
	cur = (n - 1) * b + (b - 1)
	if prd(cur) >= prd(ans):
		ans = cur
	n = n // 10
	b = b * 10
print(prd(ans))


a = list(map(int, input()))
n = len(a)
ans = 9 ** (n - 1)
t1 = 1
t = 1
for i in range(n):
	if a[i] != 0:
		t1 = t * 9 ** (n - i - 1)
		t1 = t1 * (a[i] - 1)
	t = t * a[i]
	ans = max(ans, t1)
ans = max(ans, t)
print(ans)


n = int(input())
i = 1

def pro(x):
	if x == 0:
		return 1
	return x % 10 * pro(x // 10)
ans = pro(n)
while n != 0:
	n -= n % pow(10, i)
	if n == 0:
		break
	ans = max(ans, pro(n - 1))
	i += 1
print(ans)


def calculate_digit_product(n):
	ret = n % 10
	while n // 10 > 0:
		n = n // 10
		ret *= n % 10
	return ret
n = int(input())
ans = calculate_digit_product(n)
pot = 10
while True:
	n = n - (n % pot + 1)
	if n <= 0:
		break
	ans = max(ans, calculate_digit_product(n))
	pot *= 10
print(ans)


n = int(input())
mp = 0
i = 0
if n > 9:
	while n > 9:
		t = 0
		if i != 0:
			n //= 10
			t = n - 1
		else:
			t = n
		p = 9 ** i
		while t > 0:
			p *= t % 10
			t //= 10
		if p > mp:
			mp = p
		i += 1
	print(max(9 ** (i - 1), mp))
else:
	print(n)


def solve(n):
	s = [int(i) for i in str(n)]
	if n < 10:
		return n
	if s[0] == 0:
		return 0
	return max(max(1, s[0] - 1) * 9 ** (len(s) - 1), s[0] * solve(n - s[0] * 10 ** (len(s) - 1)))

def prod(s):
	ans = 1
	for x in s:
		ans *= x
	return ans
n = int(input())
print(solve(n))


s = input()
n = len(s)
if n == 1:
	print(s)
elif s[0] == '1':
	print(9 ** (n - 1))
else:
	ans = 0
	p = 1
	for i in range(n):
		if s[i] == '0':
			break
		elif s[i + 1:] == '9' * (n - 1 - i):
			p *= int(s[i])
			ans = max(ans, p * 9 ** (n - 1 - i))
		else:
			ans = max(ans, (int(s[i]) - 1) * p * 9 ** (n - 1 - i))
			p *= int(s[i])
	print(ans)


def calc_rez(string):
	j = 1
	for i in string:
		j *= int(i)
	return j

def get_lower(SOS):
	if SOS == '0':
		return '9'
	return str(int(SOS) - 1)
a = input()
rly = True
for i in a:
	if i != '9':
		rly = False
if rly:
	print(pow(9, len(a)))
	exit()
if len(a) == 1:
	print(a)
	exit()
if a[0] == '1':
	print(pow(9, len(a) - 1))
	exit()
best_rez = calc_rez(a)
i = 0
while i < len(a):
	if a[i] == '0':
		new_s = a[:i - 1] + str(max(0, int(a[i - 1]) - 1)) + get_lower(a[i]) + '9' * (len(a) - i - 1)
	else:
		new_s = a[:i] + get_lower(a[i]) + '9' * (len(a) - i - 1)
	best_rez = max(best_rez, calc_rez(new_s))
	i += 1
print(best_rez)


s = [int(n) for n in input()]
k = 1

def f(s):
	m = 1
	for n in s:
		if n != 0:
			m *= n
		else:
			m *= 1
	return m
m = f(s)
for n in s:
	k *= n
n = len(s) - 1
while n > 0:
	if s[n] != 9:
		s[n] = 9
		s[n - 1] -= 1
	n -= 1
	m = max(m, f(s))
print(m)


def s(n):
	num = str(n)
	ans = 1
	for i in num:
		ans = ans * int(i)
	return ans
n = int(input())
m = s(n)
if n > 10000:
	ones = int(str(n)[-1])
	n = n - (ones + 1)
	temp = s(n)
	if temp > m:
		m = temp
	tens = int(str(n)[-2])
	n = n - (tens + 1) * 10
	temp = s(n)
	if temp > m:
		m = temp
	thou = int(str(n)[-3])
	n = n - (thou + 1) * 100
	temp = s(n)
	if temp > m:
		m = temp
	tent = int(str(n)[-4])
	n = n - (tent + 1) * 1000
	temp = s(n)
	if temp > m:
		m = temp
	for i in range(n, max(0, n - 1000000000), -10000):
		temp = s(i)
		if temp > m:
			m = temp
	print(m)
else:
	for i in range(n, 0, -1):
		temp = s(i)
		if temp > m:
			m = temp
	print(m)


import math
n = int(input())
s = [int(x) for x in str(n)]
ans = 1
for j in s:
	ans = ans * int(j)
for i in range(len(s) - 1, 0, -1):
	p1 = s
	p1[i] = 9
	i = i - 1
	i1 = i
	while p1[i] == 0:
		p1[i] = 9
		i = i - 1
	p1[i] = p1[i] - 1
	i = i + 1
	a = 1
	x = 0
	for o in p1:
		x = x * 10
		x = x + o
	if x < n:
		for j in p1:
			if j != 0:
				a = a * int(j)
	ans = max(ans, a)
print(ans)


def mul(n):
	a = list(str(n))
	a = map(int, a)
	p = 1
	for i in a:
		p *= i
	return p
n = int(input())
if n < 10:
	print(n)
	exit()
x = 9
while 1:
	if x * 10 + 9 > n:
		break
	x *= 10
	x += 9
ans = x
for i in range(len(list(str(n)))):
	if mul(n - n % 10 ** i - 1) > mul(ans):
		ans = n - n % 10 ** i - 1
if mul(n) > mul(ans):
	ans = n
print(mul(ans))


def nirvana():
	x = int(input())
	y = 0
	z = 0
	for i in range(11):
		if x // 10 ** i < 10:
			y = i
			z = x // 10 ** i
			break
	if y == 0:
		return x
	max = prodDigit(x)
	for i in range(1, y + 1):
		pD = prodDigit(x // 10 ** i * 10 ** i - 1)
		if max < pD:
			max = pD
	return max

def prodDigit(x):
	if x < 10:
		return x
	return x % 10 * prodDigit(x // 10)
print(nirvana())


from functools import reduce
nstr = input()
n = int(nstr)
nmap = list(map(int, nstr))
cplar = []
for i in range(len(nstr) - 1):
	if nstr[i] == '0':
		continue
	a = str(int(nstr[i]) - 1)
	b = nstr[0:i] + a + len(nstr[i + 1:]) * '9'
	if b[0] == '0':
		b = b[1:]
	b = list(map(int, b))
	cplar.append(reduce(lambda x, y: x * y, b))
cplar.append(reduce(lambda x, y: x * y, nmap))
print(max(cplar))


from sys import exit
n = int(input())

def prod(n):
	result = 1
	for elem in str(n):
		result *= int(elem)
	return result
if len(str(n)) == 1:
	print(n)
	exit()
(s_n, lst) = (str(n), [n])
for i in range(1, len(s_n)):
	lst.append(n - (n % 10 ** i + 1))
print(max(map(prod, lst)))


def prod(n):
	mult = 1
	while n > 0:
		mult = mult * (n % 10)
		n = n // 10
	return mult
n = int(input())
numbers = []
count = 0
m = n
while m != 0:
	m //= 10
	count += 1
for i in range(count):
	numbers.append(n)
	n -= n % 10 ** (i + 1) + 1
print(prod(max(numbers, key=lambda x: prod(x))))


def get_ans(s: str, init=False):
	if s == '':
		return 1
	if s[0] == '0':
		return 0
	d = int(s[0])
	r = s[1:]
	if init:
		return max(d * get_ans(r), max(1, d - 1) * 9 ** len(r))
	else:
		return max(d * get_ans(r), (d - 1) * 9 ** len(r))
n = input()
print(get_ans(n, True))


s = input().strip()
p = 1
for i in s:
	p = p * int(i)
maxx = p
curr = 1
for i in range(len(s)):
	k = curr * max(1, int(s[i]) - 1) * 9 ** (len(s) - i - 1)
	if k > maxx:
		maxx = k
	curr = curr * int(s[i])
print(maxx)


def digit(n):
	a = []
	while n > 0:
		p = n % 10
		n = n // 10
		a.append(p)
	return a

def product(a):
	p = 1
	for i in a:
		if i != 0:
			p = p * i
	return p

def answer(n):
	p = 0
	a = digit(n)
	l = len(a)
	j = int('9' * (l - 1))
	for k in range(j, n + 1):
		q = product(digit(k))
		if q > p:
			p = q
	print(p)
n = int(input())
a = digit(n)
l = len(a)
z = []
z.append(product(a))
i = 0
while i < l - 1:
	a[i] = 9
	a[i + 1] = a[i + 1] - 1
	z.append(product(a))
	i += 1
print(max(z))


n = int(input())
l = len(str(n))
res = 0
base = 1
ab = n
if l > 3:
	base = 9 ** (l - 3)
	ab = n // 10 ** (l - 3)
for num in range(1, ab):
	prod = base
	for d in str(num):
		prod *= int(d)
	res = max(res, prod)
if int(str(ab) + '9' * (l - 3)) == n:
	prod = 1
	for d in str(n):
		prod *= int(d)
	res = max(res, prod)
print(res)


def get_product(n):
	product = 1
	while n > 0 and product > 0:
		product *= n % 10
		n //= 10
	return product
n = input()
l = len(n)
n = int(n)
maximum_product = get_product(n)
for i in range(0, l):
	base = 10 ** (l - i - 1)
	v = (n // base - 1) * base + (base - 1)
	maximum_product = max(maximum_product, get_product(v))
print(maximum_product)


x = input()
flag = 0
l = [int(i) for i in x]
n = len(x)
k = 1
ans = 1
for i in l:
	ans = ans * i
for i in range(n - 1):
	d = 1
	for j in range(i):
		d = d * l[j]
	if l[i] - 1 > 0:
		d = d * (l[i] - 1)
	d = d * 9 ** (n - i - 1)
	ans = max(d, ans)
print(ans)


a = input()
b = 1
c = 0
for i in range(len(a)):
	x1 = int(a[i])
	if i == 0 and x1 == 1:
		x2 = 1
	else:
		x2 = int(a[i]) - 1
	if c < b * x2 * 9 ** (len(a) - i - 1):
		c = b * x2 * 9 ** (len(a) - i - 1)
	b *= x1
print(max(c, b))


n = int(input())
a = list(str(n))
b = [int(i) for i in a]
n = len(b)
mm = 9 ** (len(b) - 1)
for i in range(len(b)):
	m = 1
	if i > 0:
		b[n - i] = 9
		b[n - i - 1] -= 1
	for j in b:
		m = m * j
	mm = max(mm, m)
print(mm)


from functools import reduce
from operator import mul
n = int(input())
ans = reduce(mul, map(int, str(n)))
(k, p) = (10, 1)
while k <= n:
	t = n // k - 1
	if t == 0:
		ans = max(ans, 9 ** p)
	else:
		ans = max(ans, reduce(mul, map(int, str(t))) * 9 ** p)
	k *= 10
	p += 1
print(ans)


import math
n = input()
a = []
p = 1
b = []
for i in range(len(n)):
	a.append(n[i])
m = len(a)
for i in range(m):
	p = p * int(a[i])
b.append(p)
if int(a[0]) > 1 and m > 1:
	for i in range(m):
		k = (int(a[i]) - 1) * int(math.pow(9, m - i - 1))
		b.append(p)
		for j in range(i):
			k = k * int(a[j])
		b.append(k)
	print(max(b))
elif m > 1 and int(a[0]) == 1:
	print(int(math.pow(9, m - 1)))
else:
	print(n)


n = int(input())
cnt = []
cnt.append(9 ** (len(str(n)) - 1))
cnt1 = 1
n = list(map(int, list(str(n))))
for i in range(len(n)):
	cnt1 *= n[i]
cnt.append(cnt1)
for i in range(len(n)):
	if n[i] != 0:
		cur = 1
		for k in range(len(n)):
			if k < i:
				cur *= n[k]
			if k == i:
				cur *= n[k] - 1
			elif k > i:
				cur *= 9
		cnt.append(cur)
print(max(cnt))


s = input()
n = len(s)
p = 1
for k in range(n + 1):
	q = 1
	for j in range(k):
		q *= int(s[j])
	if k < n and (k != 0 or max(0, int(s[k]) - 1) != 0):
		q *= max(0, int(s[k]) - 1)
	q *= int(pow(9, max(0, n - 1 - k)))
	p = max(p, q)
print(p)


def solve(s):
	ans = 1
	for i in range(len(s)):
		ans *= int(s[i])
	return ans
n = input()
if len(n) == 1:
	print(n)
else:
	ls = []
	a = ''
	for i in range(len(n)):
		for j in range(9):
			string = a + str(9 - j) + '9' * (len(n) - i - 1)
			if int(string) <= int(n):
				ls.append(solve(string))
				a += str(9 - j + 1)
				break
	print(max(ls))


import time
n = [int(i) for i in input()]
start = time.time()
now = 1
k = len(n)
a = []
for i in range(k):
	t = now * 9 ** (k - i - 1)
	if not (i == 0 and n[i] == 1):
		t *= n[i] - 1
	a.append(t)
	now *= n[i]
a.append(now)
print(max(a))
finish = time.time()


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
n = li()
digits = [int(i) for i in n]
ma = 0
prod = 1
for j in digits:
	prod = prod * j
ma = max(ma, prod)
for i in range(1, len(digits)):
	if not digits[~i] == 0:
		digits[~i] -= 1
		j = 1
		while i - j >= 0:
			digits[~(i - j)] = 9
			j += 1
	else:
		continue
	prod = 1
	for j in range(len(digits)):
		if not (j == 0 and digits[j] == 0):
			prod = prod * digits[j]
	ma = max(ma, prod)
print(ma)


n = input()
if int(n) < 10:
	print(n)
else:
	ans = 1
	for i in n:
		ans *= int(i)
	for i in range(len(n) - 1):
		c = 1
		cur = str(int(n[:i + 1]) - 1)
		cur += '9' * (len(n) - i - 1)
		cur = str(int(cur))
		for j in cur:
			c *= int(j)
		ans = max(ans, c)
	print(ans)


import collections
import heapq
import bisect
import math
import time

class Solution2:

	def solve(self, A1, A2):
		pass

def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return b * a // gcd(b, a)

class Solution:

	def solve(self, n):
		digits = [int(c) for c in str(n)]
		curr = 1
		bel = 0
		out = 0
		for start in range(len(digits)):
			curr = 1
			bel = start > 0
			for digit in digits[start:]:
				new_curr = 0
				new_bel = 0
				for d in range(0, digit + 1):
					if d < digit:
						new_bel = max(new_bel, curr * d)
						new_bel = max(new_bel, bel * d)
					elif d == digit:
						new_bel = max(new_bel, bel * d)
						new_curr = max(new_curr, bel * d)
						new_curr = max(new_curr, curr * d)
				new_bel = max(new_bel, bel * 9)
				(curr, bel) = (new_curr, new_bel)
			out = max(out, max(curr, bel))
		return out
sol = Solution()
sol2 = Solution2()
for test_case in range(1):
	N = input()
	out = sol.solve(int(N))
	print(str(out))


def dfs(le, ri, n_str):
	tmp1 = 1
	tmp2 = 1
	tmp3 = 1
	if le == ri:
		return 1
	for i in range(le, ri):
		tmp1 *= int(n_str[i])
		tmp2 *= 9
		tmp3 *= 9
	tmp2 /= 9
	tmp3 /= 9
	tmp2 = tmp2 * (int(n_str[le]) - 1) if int(n_str[le]) > 2 else 0
	ans = max(tmp1, max(tmp2, tmp3))
	ans = max(ans, int(n_str[le]) * dfs(le + 1, ri, n_str))
	return ans
n = input()
n_str = str(n)
ans = dfs(0, len(n_str), n_str)
print(int(ans))


l = list(map(int, list(input().strip())))
n = len(l)

def prod(l):
	ans = 1
	for i in l:
		ans *= i
	return ans
p = [prod(l)]
for i in range(1, n):
	f = l[:i]
	f[-1] -= 1
	if f[-1] == 0:
		f = [9] * (n - i)
	else:
		f += [9] * (n - i)
	p.append(prod(f))
print(max(p))


n = input()
length = len(n)
n = int(n)
if n < 10:
	print(n)
	raise SystemExit
arr = []
m = n
for i in range(length):
	arr.append(m % 10)
	m //= 10
arr.reverse()

def sol(first, size, arr):
	if size - first == 1:
		return arr[first]
	if arr[first] == 1:
		return 9 ** (size - (first + 1))
	return max(arr[first] * sol(first + 1, size, arr), (arr[first] - 1) * 9 ** (size - (first + 1)))
print(sol(0, length, arr))


n = int(input())

def f(i):
	if i < 1:
		return 1 if i == 0 else 0
	md = i % 10
	if md == 9:
		return md * f(i // 10)
	else:
		return max(md * f(i // 10), 9 * f(i // 10 - 1))
print(f(n))


n = int(input())
a = str(n)
ans = 9 ** (len(a) - 1)
cur = 1
curL = len(a)
for x in a:
	curL -= 1
	if int(x) > 1:
		ans = max(ans, cur * (int(x) - 1) * 9 ** curL)
	cur *= int(x)
print(max(ans, cur))


n = [int(i) for i in input()]
rs = 1
for i in n:
	rs *= i
for (i, j) in enumerate(n):
	tmp = n.copy()
	if j == 0:
		tmp[i] = 9
		tmp[0] = -1
	else:
		tmp[i] -= 1
	for x in range(i + 1, len(n)):
		tmp[x] = 9
	tich = 1
	for x in tmp:
		if x > 0:
			tich *= x
	rs = max(rs, tich)
print(rs)


n = int(input())
current_max = n
current_max_product = 1
str_n = str(n)
for h in str(n):
	current_max_product *= int(h)
for i in range(len(str_n) - 1, 0, -1):
	answer = ''
	answer += '9' * (len(str_n) - i)
	answer += str(int(str_n[:i]) - 1)[::-1]
	answer = answer[::-1]
	product = 1
	for j in range(len(str(int(answer)))):
		product *= int(str(int(answer))[j])
	if product > current_max_product:
		current_max_product = product
print(current_max_product)


from functools import reduce

def maximum_digit_product(n):
	if len(n) == 1:
		return int(n)
	original = int(n[0]) * maximum_digit_product(n[1:])
	downgraded = int(n[0]) - 1 if int(n[0]) > 1 else 1
	downgraded_product = downgraded * reduce(lambda x, y: x * y, map(int, ['9'] * (len(n) - 1)))
	return max(original, downgraded_product)
n = input()
print(maximum_digit_product(n))


n = int(input())
if n <= 9:
	print(n)
else:
	maxx = 1
	n = str(n)
	for i in range(len(n)):
		maxx = maxx * int(n[i])
	for i in range(len(n) - 1):
		if i == 0:
			ans = 9 ** (len(n) - 1)
			if n[0] != '1':
				ans = ans * (int(n[0]) - 1)
			r = int(n[0])
		else:
			ans = 9 ** (len(n) - i - 1)
			ans = ans * (int(n[i]) - 1)
			ans = ans * r
			r = r * int(n[i])
		if ans > maxx:
			maxx = ans
	print(maxx)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = int(input())
ans = 0
s = str(n)
l = len(s)
prod1 = 1
for i in range(l):
	prod1 = prod1 * int(s[i])
prod = float('-inf')
for j in range(1, l):
	nn = str(int(s[0:j]) - 1) + '9' * (l - j)
	prod2 = 1
	if nn[0] != '0':
		for i in range(len(nn)):
			prod2 = prod2 * int(nn[i])
	else:
		for i in range(1, len(nn)):
			prod2 = prod2 * int(nn[i])
	prod = max(prod2, prod)
print(max(prod1, prod))


def digits(n):
	l = []
	while n > 0:
		l.append(n % 10)
		n = n // 10
	l.reverse()
	return l
n = int(input())
lfi = []
l = digits(n)
leng = len(l)
pro1 = 1
for i in l:
	pro1 *= i
lfi.append(pro1)
for i in range(leng):
	pro = 1
	for j in range(i):
		pro *= l[j]
	if l[i] == 0:
		continue
	if l[i] - 1 == 0 and i == 0:
		pro = pro
	else:
		pro *= l[i] - 1
	pro *= pow(9, leng - i - 1)
	lfi.append(pro)
print(max(lfi))


def func(a):
	hold = int(a) - 1
	arr = list(str(hold))
	base = 1
	for x in range(len(arr)):
		base *= int(arr[x])
	return base
n = input()
big = func(int(n) + 1)
n = list(n)
string = ''
for x in range(len(n) - 1):
	string += n[x]
	test = string + '0' * (len(n) - 1 - x)
	big = max(big, func(test))
print(big)


s = input()

def chuj(st, le):
	if le == 1:
		return int(st)
	return max(max(int(st[0]) - 1, 1) * 9 ** (le - 1), int(st[0]) * chuj(st[1:], le - 1))
print(chuj(s, len(s)))


n = int(input())
m = -1000000000.0
for k in range(len(str(n)) - 1):
	tmp = str(n)
	st = tmp[:k]
	if tmp[k] != '0' and tmp[k] != '1':
		st += chr(ord(tmp[k]) - 1)
	elif tmp[k] == '0':
		st += '9'
	st += '9' * (len(tmp) - k - 1)
	if n > int(st):
		pr = 1
		for i in range(len(st)):
			pr *= int(st[i])
		if pr > m:
			m = pr
pr = 1
tmp = str(n)
for i in range(len(tmp)):
	pr *= int(tmp[i])
if pr > m:
	print(pr)
else:
	print(m)


def prod(x):
	res = 1
	for i in x:
		res *= ord(i) - ord('0')
	return max(1, res)

def user99():
	n = input()
	ans = prod(n)
	for i in range(len(n)):
		if n[i] != '0':
			res = prod(n[:i]) if i > 0 else 1
			res *= max(1, prod(n[i]) - 1)
			res *= 9 ** (len(n) - i - 1)
			ans = max(ans, res)
	print(ans)
user99()


n = int(input())

def prod(x):
	ans = 1
	while x > 0:
		ans *= x % 10
		x //= 10
	return ans
ans = 1
for x in range(10):
	if 10 ** x > n:
		break
	y = 10 ** x * ((n - 10 ** x) // 10 ** x) + 10 ** x - 1
	if x == 0:
		y = n
	ans = max(ans, prod(y))
print(ans)


def productl(l):
	result = 1
	for i in l:
		result = result * i
	return result
n = input()
nl = list(map(int, list(n)))
max = productl(nl)
b = list()
for i in range(len(n) - 1):
	if len(n) == 1:
		pro = int(n)
	elif i == 0 and n[i] == '1':
		pro = 9 ** (len(n) - i - 1) * int(productl(b))
	elif n[i] != '0':
		pro = (int(n[i]) - 1) * 9 ** (len(n) - i - 1) * int(productl(b))
		b.append(int(n[i]))
	if max < pro:
		max = pro
print(max)


import math
n_ = int(input())
n = str(n_)
p = 1
for i in n:
	p *= int(i)
for i in range(len(n) - 1):
	p1 = 1
	for j in range(i):
		p1 *= int(n[j])
	if not (i == 0 and int(n[i]) - 1 == 0):
		p1 *= int(n[i]) - 1
	p1 *= 9 ** (len(n) - i - 1)
	if p1 > p:
		p = p1
print(p)


s = input()
num = 0
tmp = 1
for i in range(len(s)):
	k = int(s[i])
	if k == 1 and i == 0:
		num = max(num, 9 ** (len(s) - 1))
	else:
		num = max(num, tmp * (k - 1) * 9 ** (len(s) - i - 1))
	tmp *= k
num = max(num, tmp)
print(num)


n = int(input())

def findmax(n):
	if len(str(n)) == 1:
		return n
	maxp = 1
	m = list(map(int, str(n)))
	p = 1
	for i in m:
		p *= i
		maxp = max(maxp, p)
	for j in reversed(range(1, len(m))):
		p = 1
		m[j] = 9
		m[j - 1] -= 1
		if m[0] == 0:
			m[0] = 1
		for k in m:
			p *= k
		maxp = max(maxp, p)
	return maxp
print(findmax(n))


n = int(input())
digits_r = []

def prod(l):
	p = 1
	for num in l:
		p *= num
	return p
while n != 0:
	digits_r.append(n % 10)
	n = n // 10
digits = list(reversed(digits_r))
p = prod(digits)
for i in range(len(digits)):
	cand = digits[i] - 1 or 1
	cand *= prod(digits[:i])
	cand *= 9 ** (len(digits) - 1 - i)
	if cand > p:
		p = cand
print(p)


def mp():
	return map(int, input().split())

def f(x):
	r = 1
	for i in str(x):
		r *= int(i)
	return r
n = int(input())
r = f(n)
l = len(str(n))
for i in range(l):
	s = str(n)
	k = int(s[:i] + str(max(0, int(s[i]) - 1)) + '9' * (l - i - 1))
	r = max(r, f(k))
print(r)


y = []
for d in map(int, input()):
	y.append(d)
if len(y) < 3:
	if len(y) == 1:
		print(y[0])
	else:
		max1 = y[0] * y[1]
		y[-1] = 9
		if y[-2] != 1:
			y[-2] -= 1
		if max1 < y[-1] * y[-2]:
			print(y[-1] * y[-2])
		else:
			print(max1)
else:
	j = 2
	max1 = 0
	while j <= len(y):
		p = 1
		for k in y:
			p *= k
		if max1 < p:
			max1 = p
		y[-j + 1] = 9
		y[-j] -= 1
		j = j + 1
	if y[0] <= 0:
		y[0] = 1
	p = 1
	for k in y:
		p *= k
	if max1 < p:
		max1 = p
	print(max1)


def get_product(num):
	p = 1
	while num > 0:
		p *= num % 10
		num //= 10
	return p
n = int(input().strip())
if n == 10:
	print(9)
	exit()
product = get_product(n)
i = 10
while i < n:
	product = max(product, get_product(n - n % i - 1))
	i *= 10
print(product)


import math

def calc(s):
	pro = 1
	for st in s:
		pro *= ord(st) - 48
	return pro
n = str(input())
kq = 0
if len(n) == 1:
	print(n)
else:
	kq = calc(n)
	case = ''
	for i in range(len(n) - 1):
		case = '9' + case
		tmp = case
		Check = True
		for j in range(len(tmp)):
			if tmp[j] != n[len(n) - len(tmp) + j]:
				Check = False
				break
		if Check == True:
			tmp = n[0:len(n) - len(tmp) - 1] + tmp
		else:
			nho = 1
			for j in range(len(n) - len(tmp) - 1, -1, -1):
				tmp = chr((ord(n[j]) - 48 - nho) % 10 + 48) + tmp
				if tmp[0] == '9':
					nho = 1
				else:
					nho = 0
			index = 0
			while index < len(tmp) and tmp[index] == '0':
				index = index + 1
			tmp = tmp[index:len(tmp)]
		kq = max(kq, calc(tmp))
	print(kq)


import sys
MOD = 10 ** 9 + 7
input = sys.stdin.readline

def ii():
	return int(input())

def mi():
	return map(int, input().rstrip().split())

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

def li():
	return list(input().rstrip())
dp = [[0] * 2 for _ in range(10)]
N = ii()
Nlist = list(map(int, list(str(N))))
digit = len(Nlist)
dp[0][0] = Nlist[0]
dp[0][1] = max(Nlist[0] - 1, 1)
for i in range(digit - 1):
	dp[i + 1][0] = dp[i][0] * Nlist[i + 1]
	dp[i + 1][1] = max(dp[i][1] * 9, dp[i][0] * (Nlist[i + 1] - 1))
print(max(dp[digit - 1]))


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN():
	return sys.stdin.readline().strip().split()

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def pro(x):
	prod = 1
	while x:
		prod *= x % 10
		x //= 10
	return prod

def fun(l, r):
	a = str(l)
	b = str(r)
	ans = r
	for i in range(len(b)):
		if b[i] == 0:
			continue
		curr = [i for i in b]
		curr[i] = str(int(curr[i]) - 1)
		for j in range(i + 1, len(curr)):
			curr[j] = '9'
		num = 0
		for j in curr:
			num = num * 10 + int(j)
		if num >= l and pro(ans) < pro(num):
			ans = num
	return ans
n = int(input())
x = fun(1, n)
ans = 1
for i in str(x):
	ans *= int(i)
print(ans)


x = input()

def nines(n):
	m = 1
	for i in range(n):
		m *= 9
	return m

def f(n):
	if len(n) == 1:
		return int(n)
	if int(n[0]) == 1:
		return max(nines(len(n) - 1), f(n[1:]))
	else:
		return max(int(n[0]) * f(n[1:]), (int(n[0]) - 1) * nines(len(n) - 1))
print(f(x))


def readLine():
	a = input()
	return [int(i) for i in a.split(' ')]

def solve(i):
	ress = 1
	for j in range(i):
		ress *= int(n[j], 10)
	ress *= int(n[i], 10) - 1
	for j in range(i + 1, len(n)):
		ress *= 9
	return ress
n = input()
(res, ans) = (1, 1)
for i in range(len(n) - 1):
	res *= 9
t = 1
for i in n:
	t *= int(i, 10)
res = max(res, t)
for i in range(len(n)):
	res = max(res, solve(i))
print(res)


GI = lambda : int(input())
GIS = lambda : map(int, input().split())
LGIS = lambda : list(GIS())

def main():
	l = list(map(int, input()))
	l.reverse()
	mx = digitproduct(l)
	for i in range(1, len(l)):
		if l[i]:
			l[i] -= 1
			if i == len(l) - 1 and l[i] == 0:
				l.pop()
			for j in range(i):
				l[j] = 9
		mx = max(mx, digitproduct(l))
	print(mx)

def digitproduct(l):
	p = 1
	for d in l:
		p *= d
	return p
main()


import sys, math, queue
sys.setrecursionlimit(1000000)
n = [int(i) for i in list(input())]
ans = 1
for i in range(len(n)):
	ans *= n[i]
for i in range(len(n)):
	a = 1
	for j in range(i):
		a *= n[j]
	a *= int(n[i]) - 1
	a *= 9 ** (len(n) - i - 1)
	ans = max(a, ans)
print(max(ans, 9 ** (len(n) - 1)))


a = list(input())
c = 0
t = 1
for i in range(len(a)):
	j = int(a[i])
	t2 = t * (j - 1)
	t = t * j
	c = max(t2 * 9 ** (len(a) - i - 1), c)
	if i == 0 and t2 == 0:
		c = max(9 ** (len(a) - i - 1), c)
c = max(t, c)
print(c)


n = int(input())
s = str(n)
te = 0
pre = [1] * (len(s) + 1)
for i in range(len(s)):
	pre[i + 1] = pre[i] * int(s[i])
ans = 0
for i in range(len(s) - 1, -1, -1):
	if i == len(s) - 1:
		ans = pre[i + 1]
		te = 9
	elif s[i] == '0':
		te = te * 9
	else:
		if s[i] == '1':
			ans = max(ans, pre[i] * te)
			te = te * 9
			continue
		ans = max(ans, pre[i] * (int(s[i]) - 1) * te)
		te = te * 9
print(ans)


import sys

def get_ans(x):
	ans = 1
	if x == 0:
		return 0
	while x > 0:
		ans *= x % 10
		x //= 10
	return ans
a = list(input())
ans = 1
cur = int(a[0])
tmp = 9 ** (len(a) - 1)
for i in a[1:]:
	now = get_ans(cur - 1)
	if cur == 1:
		now = 1
	now *= tmp
	ans = max(ans, now)
	tmp //= 9
	cur = cur * 10 + int(i)
print(max(ans, get_ans(cur)))


n = int(input())
maxprod = 1
s = str(n)
op1 = pow(9, len(s) - 1)
maxprod = max(maxprod, op1)
for i in range(1, len(s)):
	m = int(s[0:i]) - 1
	op2 = pow(9, len(s) - i)
	while m > 0:
		op2 *= m % 10
		m = m // 10
	maxprod = max(maxprod, op2)
op3 = 1
while n > 0:
	op3 *= n % 10
	n = n // 10
maxprod = max(maxprod, op3)
print(maxprod)


def int_raw():
	return int(input())

def ss_raw():
	return input().split()

def ints_raw():
	return list(map(int, ss_raw()))
N = int_raw()
digis = list(range(2, 10))

def ans(n):
	if n < 10:
		return n
	(div10, mod10) = divmod(n, 10)
	if mod10 == 0:
		return ans(n - 1)
	elif mod10 == 9:
		return 9 * ans(div10)
	else:
		return max(ans(n - mod10 - 1), mod10 * ans(div10))
print(ans(N))


n = input()
q = len(n) - 1
ma = 9 ** q
q = 1
for i in range(len(n)):
	if n[i] != '0':
		e = q
		e *= int(n[i]) - 1
		e *= 9 ** (len(n) - i - 1)
		ma = max(ma, e)
	q *= int(n[i])
w = 1
for i in n:
	w *= int(i)
print(max(ma, w))


def product(z):
	product2 = 1
	for j in range(len(z)):
		product2 = product2 * z[j]
	return product2
d = [int(x) for x in input()]
n = len(d)
r = 0
m = product(d)
if m > r:
	r = m
for i in range(n - 1, 0, -1):
	d[i] = 9
	if d[i - 1] - 1 > 0:
		d[i - 1] = d[i - 1] - 1
		m = product(d)
		if m > r:
			r = m
print(max(r, 9 ** (n - 1)))


n = list(map(int, input().strip()))
c = 0
b = 1
for i in range(len(n)):
	if i == 0 and n[i] == 1:
		x2 = 1
	else:
		x2 = n[i] - 1
	re = b * x2 * 9 ** (len(n) - i - 1)
	if c < re:
		c = re
	b *= n[i]
print(max(b, c))


def product(n):
	prod = 1
	while n > 0:
		rem = n % 10
		prod = prod * rem
		n = n // 10
	return prod
number = input()
if int(number) < 10:
	print(number)
	exit()
else:
	num = int(number)
	temp = 10
	sols = []
	for i in range(len(number)):
		sols.append(num - num % temp - 1)
		temp *= 10
	final_sol = [product(num)]
	for x in sols:
		final_sol.append(product(x))
print(max(final_sol))


def getv(x):
	x1 = 1
	if x[-1] == 0:
		x.pop()
	for i in x:
		x1 *= int(i)
	return x1
n = input()
n = list(n)
n = n[::-1]
n1 = n[:]
ma = getv(n)
for i in range(len(n) - 1):
	n1[i] = 9
	n1[i + 1] = int(n1[i + 1]) - 1
	ma = max(ma, getv(n1))
print(ma)


from functools import reduce
import operator as op

def main():
	z = int(input())
	y = str(z)
	a = list(map(int, list(y)))
	maxi = reduce(lambda a, b: a * b, a)
	for i in range(len(a)):
		if i == 0 and a[i] == 1:
			maxi = 9 ** (len(a) - 1)
			break
		elif i == 0:
			if maxi < 9 ** (len(a) - 1) * (a[i] - 1):
				maxi = 9 ** (len(a) - 1) * (a[i] - 1)
		elif a[i] == 1:
			break
		elif maxi < 9 ** len(a[i + 1:]) * (a[i] - 1) * reduce(lambda x, y: x * y, a[:i]):
			maxi = 9 ** len(a[i + 1:]) * (a[i] - 1) * reduce(lambda x, y: x * y, a[:i])
	print(maxi)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	a = [int(c) for c in S()]
	r = 1
	for c in a:
		r *= c
	l = len(a)
	for i in range(l - 1):
		if a[i] < 1:
			continue
		tr = 1
		for j in range(l):
			if j < i:
				tr *= a[j]
			elif j == i:
				if j != 0 or a[j] > 1:
					tr *= a[j] - 1
			else:
				tr *= 9
		if r < tr:
			r = tr
	return r
print(main())


n = [int(x) for x in list(input())]
counter = 0
answer = 0
pro = n[0]
for i in range(1, len(n)):
	if n[i - 1] - 1 > 0:
		pro /= n[i - 1]
		pro *= n[i - 1] - 1
		counter = pro * 9 ** (len(n) - i)
		pro /= n[i - 1] - 1
		pro *= n[i - 1] * n[i]
		answer = max(answer, counter)
pro = 1
for item in n:
	pro *= item
answer = max(answer, 9 ** (len(n) - 1), pro)
print(int(answer))


t = 1
for _ in range(t):
	n = int(input())
	s = str(n)
	l = len(s)
	if l == 1:
		print(n)
		continue
	ans = 1
	for i in s:
		ans *= int(i)
	temp = 1
	for i in range(l - 1):
		temp *= int(s[i])
		if int(s[i + 1]) > 0:
			ans = max(ans, temp * (int(s[i + 1]) - 1) * pow(9, l - (i + 2)))
	ans = max(9 ** (l - 1) * max(1, int(s[0]) - 1), ans)
	print(ans)


def length(n):
	a = 1
	while n // 10 != 0:
		a += 1
		n = n // 10
	return a

def first(n):
	return n // 10 ** (length(n) - 1)

def fun(n):
	if n // 10 == 0:
		return n
	if first(n) == 1:
		return 9 ** (length(n) - 1)
	else:
		return max(first(n) * fun(n % 10 ** (length(n) - 1)), (first(n) - 1) * 9 ** (length(n) - 1))
n = int(input())
print(fun(n))


n = input().strip()
n = list(map(int, n))
ans = 0
cum = 1
if n[0] == 1:
	ans = 9 ** (len(n) - 1)
for (idx, num) in enumerate(n):
	if num:
		ans = max(ans, cum * (num - 1) * 9 ** (len(n) - idx - 1))
	cum *= num
ans = max(cum, ans)
print(ans)


n = list(input())

def prod(l):
	l = list(str(int(''.join(l))))
	res = 1
	for i in l:
		res *= int(i)
	return res
m = prod(n)
for i in range(0, len(n)):
	if n[i] == '0':
		continue
	cpy = n.copy()
	cpy[i] = str(int(cpy[i]) - 1)
	for j in range(i + 1, len(n)):
		cpy[j] = '9'
	m = max(prod(cpy), m)
print(m)


n = input()

def mult(list):
	res = 1
	for x in list:
		res = res * x
	return res
if len(n) != 1:
	arr = [mult([*map(int, list(n))])]
	tmp = list(map(int, list(reversed(n))))
	for i in range(len(tmp) - 1):
		tmp[i] = 9
		if tmp[i + 1] != 0:
			tmp[i + 1] = tmp[i + 1] - 1
		arr.append(mult([i for i in tmp if i > 0]))
	print(max(arr))
else:
	print(int(n))


str_n = input()
dig_n = []
for x in str_n:
	dig_n.append(int(x))
dig_n.reverse()
i = 0
max_prod = 1
while i < len(dig_n):
	if dig_n[i] * max_prod < max(1, dig_n[i] - 1) * pow(9, i):
		max_prod = max(1, dig_n[i] - 1) * pow(9, i)
		dig_n[i] -= 1
		for j in range(0, i):
			dig_n[j] = 9
	else:
		max_prod *= dig_n[i]
	i += 1
print(max_prod)


n = int(input())
s = [int(i) for i in str(n)]
ls = len(s)
p = 1
c = 0
mp = s[0]
pf = 1
for i in s:
	if i == 1 or i == 0:
		k = 1
	else:
		k = i - 1
	p *= k
	p2 = 9 ** (ls - c - 1)
	mp = max(mp, p * p2)
	c += 1
	p //= k
	p *= i
	pf *= i
print(max(mp, pf))


def niet_ban(n):
	n = int(n)
	t1 = 1
	while n != 0:
		t1 = t1 * (n % 10)
		n = int(n / 10)
		if n == 0:
			break
	return int(t1)

def ngoaile(n):
	n = int(n)
	max = 0
	for i in range(1, n + 1):
		if niet_ban(i) > max:
			max = niet_ban(i)
	return max

def xuli(n):
	n = int(n)
	if n > 20:
		t = 0
		for i in range(n + 1):
			if (n - i) % 10 == 9:
				t = n - i
				break
		k = 9 * xuli(t / 10)
		k1 = niet_ban(n)
		if k > k1:
			return k
		else:
			return k1
	else:
		return ngoaile(n)
n = int(input())
k = xuli(n)
print(k)


def prod(a):
	res = 1
	leading = True
	for el in a:
		if leading and el == 0:
			continue
		leading = False
		res *= el
	return res
a = list(map(int, list(input())))
res = prod(a)
for i in range(len(a) - 1, -1, -1):
	if a[i] != 0:
		a[i] = a[i] - 1
		for j in range(i + 1, len(a)):
			a[j] = 9
		res = max(res, prod(a))
print(res)


n = int(input())
x = n
cnt = 0
while x > 0:
	cnt += 1
	x //= 10
l = [n]
for i in range(1, cnt):
	p = n % 10 ** i
	p += 1
	l.append(n - p)
ans = 1
for i in range(cnt):
	prod = 1
	while l[i] > 0:
		prod *= l[i] % 10
		l[i] //= 10
	ans = max(ans, prod)
print(ans)


def solve(n):
	if n == 0:
		return 1
	elif n == -1:
		return 0
	x = n // 10
	return max(int(n % 10) * solve(x), 9 * solve(x - 1))
num = int(input())
print(solve(num))


digits = list(map(int, list(input())))
maxproduct = 0
for i in range(len(digits)):
	if digits[i] != 0:
		product = 1
		j = 0
		while j != i:
			product *= digits[j]
			j += 1
		product *= max(digits[i] - 1, 1)
		j += 1
		while j < len(digits):
			product *= 9
			j += 1
		maxproduct = max(product, maxproduct)
direct = 1
for d in digits:
	direct *= d
print(max(maxproduct, direct))


def product(x):
	prod = 1
	while x:
		prod = prod * (x % 10)
		x = int(x / 10)
	return prod

def calculate(lower, upper):
	strofup = str(upper)
	ans = upper
	for i in range(0, len(strofup)):
		if strofup[i] == '0':
			continue
		curr = list(strofup)
		curr[i] = str(ord(curr[i]) - ord('0') - 1 + ord('0'))
		for j in range(i + 1, len(strofup)):
			curr[j] = str(ord('9'))
		number = 0
		for c in curr:
			if int(c) < 48:
				number = number * 10 + int(c)
			else:
				number = number * 10 + (int(c) - ord('0'))
		if number > lower and product(number) > product(ans):
			ans = number
	return ans
n = int(input())
x = calculate(1, n)
x = product(x)
print(x)


s = input()
res = -float('inf')
mul = 1
for i in range(len(s)):
	if s[i] == '0':
		break
	part = 9 ** (len(s) - i - 1)
	res = max(res, (int(s[i]) - 1) * mul * (part if part > 0 else 1))
	mul *= int(s[i])
kek = 1
for x in s:
	kek *= int(x)
print(max([res, kek, 9 ** (len(s) - 1)]))