from collections import Counter, deque

# from copy import copy, deepcopy

# from fractions import gcd

# from functools import reduce

# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

# import math

# import numpy as np

import sys

sys.setrecursionlimit(10 ** 5 + 10)

# input = sys.stdin.readline



def resolve():

    N=int(eval(input()))

    A=list(map(int,input().split()))

    AA=Counter(A)

    maxval=0

    for i in list(AA.keys()):

        maxval=max(AA[i-1]+AA[i]+AA[i+1],maxval)



    print(maxval)







resolve()
from collections import Counter, deque

# from copy import copy, deepcopy

# from fractions import gcd

# from functools import reduce

# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

# import math

# import numpy as np

# from operator import xor

import sys

sys.setrecursionlimit(10 ** 5 + 10)

# input = sys.stdin.readline



def resolve():



    N=int(eval(input()))

    A=list(map(int,input().split()))



    AA=Counter(A)



    ans=0

    if N==1:

        print((1))

    elif N==2:

        if abs(A[0]-A[1])<=1:

            print((2))

        else:

            print((1))

    else:

        for i in range(N-2):

            ans=max(AA[i]+AA[i+1]+AA[i+2],ans)

        print(ans)



resolve()
from collections import Counter, deque

# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys

sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    AA = Counter(A)
    maxval = 0
    for i in list(AA.keys()):
        maxval = max(AA[i - 1] + AA[i] + AA[i + 1], maxval)
    print(maxval)


resolve()

from collections import Counter, deque

# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys

sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
    N = int(eval(input()))
    A = list(map(int, input().split()))
    AA = Counter(A)
    ans = 0
    if N == 1:
        print((1))
    elif N == 2:
        if abs(A[0] - A[1]) <= 1:
            print((2))
        else:
            print((1))
    else:
        for i in range(N - 2):
            ans = max(AA[i] + AA[i + 1] + AA[i + 2], ans)
        print(ans)


resolve()

+# from operator import xor -    maxval = 0 -    for i in list(AA.keys()): -        maxval = max(AA[i - 1] + AA[i] + AA[i + 1], maxval) -    print(maxval) +    ans = 0 +    if N == 1: +        print((1)) +    elif N == 2: +        if abs(A[0] - A[1]) <= 1: +            print((2)) +        else: +            print((1)) +    else: +        for i in range(N - 2): +            ans = max(AA[i] + AA[i + 1] + AA[i + 2], ans) +        print(ans)