import Data.List

main :: IO ()
main = do
  getLine
  ds <- map read . words <$> getLine
  print $ solve ds

-- |
-- >>> solve [9, 1, 4, 4, 6, 7]
-- 2
-- >>> solve [9, 1, 14, 5, 5, 4, 4, 14]
-- 0
-- >>> solve [99592, 10342,29105, 78532, 83018, 11639, 92015, 77204, 30914, 21912, 34519, 80835, 100000, 1]
-- 42685
solve :: [Int] -> Int
solve ds = head $ dropWhile (< 0) $ zipWith (-) sds rds
  where
    sds = sort ds
    rds = reverse sds

