{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> VU.Vector Int -> Int
solve !n !ws = minimum
  [ let (w1, w2) = VU.splitAt i ws in abs (VU.sum w1 - VU.sum w2)
  | i <- [0 .. n - 1]
  ]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  ws <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n ws
