import Data.Maybe

main :: IO ()
main = do
  _ <- getLine
  ls <- fmap read . words <$> getLine :: IO [Int]
  let ls' = foldl solve [] ls
  print $ maximum $ snd <$> ls'

solve :: [(Int,Int)] -> Int -> [(Int,Int)]
solve env val = [(p,p' + 1),(o,o' + 1),(n,n' + 1)] ++ env where
  p = val - 1
  o = val
  n = val + 1
  p' = fromMaybe 0 $ lookup p env
  o' = fromMaybe 0 $ lookup o env
  n' = fromMaybe 0 $ lookup n env
