require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

N,_=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}

tcc = 1
seqcnt = 0
size = A[0]
# firstly generate after all count
i = 0
while(i<=N-1)
	if(A[i] == size)
		i += 1
		seqcnt += 1
	else
		break
	end
end
tcc = 1
# puts seqcnt
# puts size
while((seqcnt) > tcc**size)
	tcc += 1
end
if(i==N)
	puts tcc
	exit(0)
end
# dputs tcc
# nextcharflg = false
# if(tcc**prevsize - tcc**(prevsize-1) <= i+1)
# 	nextcharflg = true
# end
while(true)
	prevseqcnt = seqcnt
	prevsize = size
	prevseqcnt = seqcnt
	prevtcc = tcc

	seqcnt = 0
	size = A[i]
	while(i<=N-1)
		# p "i is"
		# p i
		# p "size is"
		# p size
		# p "A[i] is"
		# p A[i]
		if(A[i] == size)
			i += 1
			seqcnt += 1
			# puts "hoge"
		else
			# puts "hoge"
			break
		end
	end
	# puts i
	# calc
	# p prevsize
	# p size
	if(size > prevsize)
		# tcc incre
		base = (prevseqcnt-1) * tcc ** (size - prevsize)
		while(tcc**size - (base) < seqcnt)
			tcc += 1
		end
	# elsif(size == prevsize)
	elsif(size < prevsize)
		# tcc incre
		base = prevseqcnt / (prevtcc**(prevsize-size))
		while(tcc**size - (base+1) < seqcnt)
			tcc += 1
		end
	end
	# exit
	# p "final i is"
	# p i
	if(i==N)
		puts tcc
		exit(0)
	end
end
