import collections





if __name__ == '__main__':

    n = int(eval(input()))

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



    tmp_A = []

    for a in A:

        tmp_A.append(a-1)

        tmp_A.append(a)

        tmp_A.append(a+1)



    c = collections.Counter(tmp_A)

    most_common_element = c.most_common()[0][0]



    answer = 0

    for a in A:

        if a == most_common_element or a-1 == most_common_element or a+1 == most_common_element:

            answer += 1

    print(answer)



import collections





if __name__ == '__main__':

    n = int(eval(input()))

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



    c = collections.Counter(a_list)



    dic_cnt = dict(c.most_common())



    answer = -1

    for k in list(dic_cnt.keys()):

        cnt = dic_cnt[k]

        if k-1 in list(dic_cnt.keys()):

            cnt += dic_cnt[k-1]

        if k+1 in list(dic_cnt.keys()):

            cnt += dic_cnt[k+1]

        answer = max(answer,cnt)

    print(answer)



import collections

if __name__ == "__main__":
    n = int(eval(input()))
    A = list(map(int, input().split()))
    tmp_A = []
    for a in A:
        tmp_A.append(a - 1)
        tmp_A.append(a)
        tmp_A.append(a + 1)
    c = collections.Counter(tmp_A)
    most_common_element = c.most_common()[0][0]
    answer = 0
    for a in A:
        if (
            a == most_common_element
            or a - 1 == most_common_element
            or a + 1 == most_common_element
        ):
            answer += 1
    print(answer)

import collections

if __name__ == "__main__":
    n = int(eval(input()))
    a_list = list(map(int, input().split()))
    c = collections.Counter(a_list)
    dic_cnt = dict(c.most_common())
    answer = -1
    for k in list(dic_cnt.keys()):
        cnt = dic_cnt[k]
        if k - 1 in list(dic_cnt.keys()):
            cnt += dic_cnt[k - 1]
        if k + 1 in list(dic_cnt.keys()):
            cnt += dic_cnt[k + 1]
        answer = max(answer, cnt)
    print(answer)

-    A = list(map(int, input().split())) -    tmp_A = [] -    for a in A: -        tmp_A.append(a - 1) -        tmp_A.append(a) -        tmp_A.append(a + 1) -    c = collections.Counter(tmp_A) -    most_common_element = c.most_common()[0][0] -    answer = 0 -    for a in A: -        if ( -            a == most_common_element -            or a - 1 == most_common_element -            or a + 1 == most_common_element -        ): -            answer += 1 +    a_list = list(map(int, input().split())) +    c = collections.Counter(a_list) +    dic_cnt = dict(c.most_common()) +    answer = -1 +    for k in list(dic_cnt.keys()): +        cnt = dic_cnt[k] +        if k - 1 in list(dic_cnt.keys()): +            cnt += dic_cnt[k - 1] +        if k + 1 in list(dic_cnt.keys()): +            cnt += dic_cnt[k + 1] +        answer = max(answer, cnt)