program main
implicit none
integer :: n, i, res, r
integer , allocatable :: w(:)

read(*,*) n
allocate( w(n) )
read(*,*) w(1:n)

res = sum(w)
do i = 1, n-1
r = min( res, abs( sum(w(1:i))-sum(w(i+1:n)) ) )
res = r
end do
write(*,'(i0)') res

end program main
