import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  ws <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    (s0 : ss) = scanr1 (+) ws
  print . minimum . map abs . subtract s0 $ (2 *) <$> ss

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
