import           Data.List
import           Control.Applicative
import           Control.Monad
import           Control.Monad.State

hoge :: [Int] -> State [Int] Int
hoge []       = return 0
hoge (a : as) = do
  rs <- get
  let nrs = a : takeWhile (>= (a - 2)) rs
  put nrs
  (\a -> maximum [length nrs, a]) <$> hoge as

main = do
  n  <- readLn
  ns <- sort . take n . map (read :: String -> Int) . words <$> getLine
  print $ evalState (hoge ns) []
