import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

long solve (int n)
{
	readln;
	auto a = readln.splitter.map !(to !(long)).array;
	auto total = sum (a);
	long cur = 0;
	long res = long.max;
	foreach (i, c; a)
	{
		if (i > 0)
		{
			res = min (res, abs (total - 2 * cur));
		}
		cur += c;
	}
	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		writeln (solve (n));
	}
}
