program Balance
    implicit none
    integer(4):: n, mi, i
    integer(4),allocatable:: w(:)

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

    mi = 100000

    do i=1,n-1
        mi = min(mi, abs(sum(w(1:i))-sum(w(i+1:n))))
    end do

    print*, mi
    
end program Balance