#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n);
	long long x = 0, y = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		y += a[i];
	}
	long long  ans = 1e11;
	for (int i = 0; i < n-1; i++) {
		y -= a[i];
		x += a[i];
		ans = min(abs(x - y), ans);
	}
	cout << ans << endl;

	return 0;
}

