main = do
  n<-readLn
  ws<-map read.words<$>getLine
  print $ solve n ws

solve n ws = minimum [ abs $ sum as - sum bs
                   | t <- [1..n]
                   , let as = take t ws
                   , let bs = drop t ws]