import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);

	ulong last, ans = 1;
	long reserve;

	foreach (i, token; split(my_readln()))
	{
		auto a = to!ulong(token);
		if (i != 0)
		{
			if (a < last)
			{
				if (reserve <= 1)
				{
					++ans;
					reserve = pow(ans, a) - 1;
					//stderr.writeln("1.1 ", reserve);
				}
				else
				{
					auto used = (pow(ans, last) - reserve) / pow(ans, last - a);
					reserve   = pow(ans, a) - used - 1;
					//stderr.writeln("1.2 ", reserve);
				}
			}
			else if (a == last)
			{
				if (reserve <= 1)
				{
					++ans;
					reserve = pow(ans, a) - 1;
					//stderr.writeln("2.1 ", reserve);
				}
				else
				{
					--reserve;
					//stderr.writeln("2.2 ", reserve);
				}
			}
			else
			{
				auto used = (pow(ans, last) - reserve) * pow(ans, a - last);
				reserve   = pow(ans, a) - used;
				//stderr.writeln("3 ", reserve);
			}
		}
		last = a;
	}

	writeln(ans);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}