from bisect import bisect
n, d = map(int, input().split())
s = []
for i in range(n):
    x = int(input())
    s.append(x)
s.sort()

l = s[0]
r = s[-1]

ans = 0
for i in range(l - 3, r + 4):
    tmp = bisect(s, i + 3) - bisect(s, i - 3)
    ans = max(ans, tmp)
print(ans)
