import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Char (isSpace)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine :: IO (VU.Vector Int)
  print $ solve as (n-1)

solve :: VU.Vector Int -> Int -> Int
solve v n 
    | n == 1 = abs (x-y)
    | otherwise = min (abs (x-y)) (solve v (n-1))
  where x = VU.sum $ VU.take n v
        y = VU.sum v - x