n,k = map(int,input().split())
a = []
for _ in range(n):
  a.append(int(input()))  
b = [0]*n
c = [0]*n

for i in range(n):
  temp = [1]
  for j in range(i-1,-1,-1):
    if c[j] == 0:
      x = a[j]-a[i]
      if abs(x)<=3:
        temp.append(b[j]+1)
        c[j] = 1
  b[i] = max(temp)
print(max(b))