solver::[Int]->Int->Int
solver xs n = let s = sum xs in minimum [abs(s - 2*(sum (take i xs))) |i<-[1..n-1]]

main::IO()
main=do
  nc<-getLine
  let n = read nc
  datc<-getLine
  let dat = map read (words datc)
  print (solver dat n)