#include <bits/stdc++.h>

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

int main(){
int n;
cin>>n;
ll a[n];
ll sum=0;
rep(i,n){
  cin>>a[i];
  sum+=a[i];
}
ll ans=10000000007;
ll x=0;
rep(i,n-1){
x+=a[i];
sum-=a[i];
ans=min(ans,abs(x-sum));
}
cout<<ans<<endl;

  return 0;
}
