program ABC097C
    implicit none
    integer::n,i,ans,suml
    integer,allocatable::a(:),acc(:)
    read*,n
    allocate(a(n),acc(n))
    read*,a
    suml = sum(a)
    acc(1) = a(1)
    do i = 2, n
        acc(i) = acc(i-1) + a(i)
    end do
    
    ans = 10**9
    do i = 1, n-1
        ans = min(abs(2*acc(i) - suml),ans)
    end do
    print*,ans
end program ABC097C