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

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

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!uint;
	long[] a;
	foreach (token; my_readln.split)
	{
		a ~= token.to!long;
	}

	long[uint[2]] memo;

	long f(uint[2] pos, int turn)
	{
		if (pos[0] == pos[1]) return 0;
		auto m = memo.get(pos, 0);
		if (m != 0) return m;

		auto r1 = f([pos[0]+1, pos[1]], -turn) + a[pos[0]] * turn;
		auto r2 = f([pos[0], pos[1]-1], -turn) + a[pos[1]-1] * turn;
		auto r  = turn == 1 ? max(r1, r2) : min(r1, r2);
		memo[pos] = r;
		return r;
	}

	writeln(f([0, N], 1));
	stdout.flush();
}