# ARC082C - Together (ABC072C)

n = int(eval(input()))

lst = list(map(int, input().rstrip().split()))

ans = [0] * 100001

for i in lst:

    ans[i] += 1

print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:])))))))
# ARC082C - Together (ABC072C)

def main():

    n = int(eval(input()))

    lst = list(map(int, input().rstrip().split()))

    ans = [0] * 100001

    for i in lst:

        ans[i] += 1

    print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:])))))))





if __name__ == "__main__":

    main()
# ARC082C - Together (ABC072C)
n = int(eval(input()))
lst = list(map(int, input().rstrip().split()))
ans = [0] * 100001
for i in lst:
    ans[i] += 1
print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:])))))))

# ARC082C - Together (ABC072C)
def main():
    n = int(eval(input()))
    lst = list(map(int, input().rstrip().split()))
    ans = [0] * 100001
    for i in lst:
        ans[i] += 1
    print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:])))))))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -lst = list(map(int, input().rstrip().split())) -ans = [0] * 100001 -for i in lst: -    ans[i] += 1 -print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:]))))))) +def main(): +    n = int(eval(input())) +    lst = list(map(int, input().rstrip().split())) +    ans = [0] * 100001 +    for i in lst: +        ans[i] += 1 +    print((max(list(map(sum, list(zip(ans, ans[1:], ans[2:]))))))) + + +if __name__ == "__main__": +    main()