n, k = map(int, input().split())
lis = []
for i in range(n): lis.append(int(input()))
dp = [1]*n
for i in range(n):
  for j in range(i):
    if abs(lis[i]-lis[j])<=3: dp[i] = max(dp[i], dp[j]+1)
print(max(dp))
