import Data.List
import qualified Data.ByteString.Char8 as B

readInt :: B.ByteString -> Int
readInt = maybe undefined fst . B.readInt

readInts :: B.ByteString -> [Int]
readInts = map readInt . B.words

main = do
  getLine
  as <- readInts <$> B.getLine
  print (together as)

together as = succ $ maximum $ (0:) $ map (length . takeWhile (<=2) . scanl1 (+)) $ collectBy (\x y -> x<2&&y<2) ds
  where
    sas = sort as
    ds = zipWith (-) (tail sas) sas

collectBy _ [] = []
collectBy op [x] = [[x]]
collectBy op (x1:x2:xs)
  | op x1 x2 = let (g:gs) = collectBy op (x2:xs) in (x1:g) : gs
  | otherwise = collectBy op (x2:xs)
