program main
	implicit none
	integer :: i, j, n, minimum, summary, tmp
    integer, allocatable :: W(:)
    
    read(*, *) n
    allocate(w(n))
    read(*, *) (w(i), i = 1, n)
    summary = 0
    do i = 1, n
    	summary = summary + w(i)
    enddo
    tmp = 0
    minimum = summary
    do i = 1, n-1
    	tmp = tmp + w(i)
        if (abs(summary - tmp) - abs(tmp).lt.(minimum)) minimum = abs(summary - tmp) - abs(tmp)
    enddo
    write(*, *) minimum 
stop
end program main