open Str

module L =
  struct
    include List
  
    let rec span f = function
        [] -> ([],[])
      | h :: t when f h -> let (xs, ys) = span f t in (h::xs, ys)
      | l -> ([],l)

    let rec group f = function
      | [] -> []
      | h :: t -> let (xs, ys) = span (f h) t in (h :: xs) :: group f ys

  end

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let rec together ct = function
    (x1, l1) :: (x2, l2) :: (x3, l3) :: tl when x1 + 1 = x2 && x2 + 1 = x3 -> together (max ct (l1+l2+l3)) ((x2, l2) :: (x3, l3) :: tl)
  | (x1, l1) :: (x2, l2) :: tl when x1 + 1 = x2 -> together (max ct (l1+l2)) ((x2, l2) :: tl)
  | (x1, l1) :: tl -> together (max ct l1) tl
  | [] -> ct

let () =
  let _ = read_line () in
  let lst = read_list int_of_string |> L.sort compare |> L.group (=) |> L.map (fun l -> (L.hd l, L.length l))in
  together 0 lst |> string_of_int |> print_endline
