#!/bin/python import sys n = int(raw_input().strip()) a = map(int,raw_input().strip().split(' ')) counts = {} for el in a: if counts.get(el): counts[el] += 1 else: counts[el] = 1 list_counts = [] for k, v in counts.iteritems(): list_counts.append([k, v]) sorted_counts = sorted(list_counts, key=lambda x: x[0]) max_len = 0 prev = sorted_counts[0] max_count = sorted_counts[0][1] for el in sorted_counts[1:]: if max_count < el[1]: max_count = el[1] if abs(el[0] - prev[0]) == 1: if prev[1] + el[1] > max_len: max_len = prev[1] + el[1] prev = el if max_len < max_count: max_len = max_count print max_len