#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
	int n, a;
	scanf("%d", &n);
	ll tmp = 0, sum[n];
	rep(i, n){
		scanf("%d", &a);
		sum[i] = a + tmp;
		tmp += a;
	}
	ll minv = 1e+14;
	rep(i, n-1){
		minv = min(minv, abs(sum[n-1] - sum[i] * 2));
	}
	printf("%lld\n", minv);
	return 0;
}