program kadai
implicit none
integer  ::  n,j
integer,allocatable  ::  w(:)
integer  ::  si(2)
integer  ::  ans1,ans2


read(*,*) n
allocate(w(n))
w=0
read(*,*) w
si=0
do j=1,n-1
    si(1)=sum(w(1:j))
    si(2)=sum(w(j+1:n))
    ans2=abs(si(1)-si(2))
    if (j==1) then
        ans1=ans2
    end if
    if(ans1>ans2 .and. j>1) then
        ans1=ans2
    end if
end do

write(*,*) ans1

end program kadai