{-# LANGUAGE BangPatterns          #-}

import Control.Monad
import Control.Applicative
import Data.Array.IO

maxNum :: Int
maxNum = 100000

main :: IO()
main = do
    n <- readLn :: IO Int
    a <- map read .words <$> getLine :: IO [Int]
    count <- newArray (0, maxNum + 1) 0 :: IO (IOUArray Int Int)
    forM_ [0..(n - 1)] $ \i -> do
        let v = a!!i
        c1 <- readArray count v
        writeArray count v (c1 + 1)
        if v > 0 then do
            c2 <- readArray count (v - 1)
            writeArray count (v - 1) (c2 + 1)
        else do
            return ()
        if v < maxNum then do
            c3 <- readArray count (v + 1)
            writeArray count (v + 1) (c3 + 1)
        else do
            return ()
    elems <- getElems count
    print $ maximum elems
