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

-- String, Int, Char, IO
-- putStrLn
-- e.g.
-- 1
-- [a] <- map read . words <$> getLine => [1] -> a == 1
-- 1
-- a <- readLn
-- 1 2 3
-- lst <- map read . words <$> getLine => [1, 2, 3]
-- 1 2 3
-- [l, m, n] <- map read . words <$. getLine :: IO [Int] => [1, 2, 3]
-- 'a'
-- c <- getChar => c == 'a'
--
-- slst <- replicateM h getLine

getBysplit = map read . words <$> getLine

main :: IO()
main = do
  [n] <- getBysplit :: IO [Int]
  als <- getBysplit :: IO [Int]
  print $ solve als

countBySame :: (Ord a) => [a] -> [(a, Int)]
countBySame [] = []
countBySame lst = let
                    x:xs = sort lst
                    ((e, c), lst') = sameElem x xs 0
                    in (e, c):countBySame lst'
    where
      sameElem :: (Ord a) => a -> [a] -> Int -> ((a, Int), [a])
      sameElem x [] count = ((x, count+1), [])
      sameElem x (y:ys) count
                    | x ==  y = sameElem x ys (count+1)
                    | x /= y = ((x, count+1), y:ys)

solve :: [Int] -> Int
solve lst = f 0 (-1, 0) lst'
    where
      lst' = countBySame lst
      f :: Int -> (Int, Int) -> [(Int, Int)] -> Int
      f ans (x, xc) [] =  if xc > ans
                            then xc
                            else ans
      f ans (x, xc) [(y, yc)]
                | x == y-1 = max (xc+yc) ans
                | x /= y-1 = f (max xc ans) (y, yc) []
      f ans (x, xc) ((y, yc):(z, zc):rest) = let
                                            a = if x == y-1
                                                  then xc
                                                  else 0
                                            b = if y == z-1
                                                  then zc
                                                  else 0
                                            in f (max ans (a+yc+b)) (y, yc) ((z, zc):rest)


countBySame' :: [Int] -> [Int]
countBySame' [] = []
countBySame' lst = let x:xs = sort lst  ; (n, list) = (samelist x xs 0) in n : (countBySame' list)
  where
    samelist :: Int -> [Int] ->  Int -> (Int, [Int])
    samelist a [] n = (n+1, [])
    samelist a (x:xs) n
                  | a == x = samelist a xs (n+1)
                  | a /= x = (n+1, x:xs)


solve' :: [Int] -> Int
solve' lst = let
              list = countBySame' lst
              (ml, pl) = (map (1+) list, map (1-) list)
              list' = zipWith3 (\a b c -> a + b + c) ml list pl
              m = maximum list'
              in m
