implicit none
integer :: N
integer, allocatable :: W(:)
integer :: i, ds, dsmin, s1, s2, T

read *,N
allocate(W(N))
read *, (W(i),i=1,N)

s2 = sum(W)

dsmin = s2
s1 = 0
do T = 1, N-1
   s1 = s1 + W(T)
   s2 = S2 - W(T)
   ds = abs(s1-s2)
   if (ds < dsmin) then
      dsmin = ds
   else
      exit  ! Once weight starts to increase, no longer consider.
   endif
enddo

write(6,'(i0)') dsmin
stop
end