#include <bits/stdc++.h>

#define F first
#define S second
#define endl "\n"
#define ll long long
#define ii pair<int, int>

using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    vector<ll> arr(n);

    for(int i = 0; i < n; i++)
        cin >> arr[i], arr[i] += (i > 0 ? arr[i - 1] : 0LL);

    for(int i = 0; i < n - 1; i++)
        arr[i] = labs(arr.back() - 2 * arr[i]);

    cout << *min_element(arr.begin(), arr.end() - 1);
}