N, K = map(int, input().split())
A = [0] + [int(input()) for _ in range(N)]

dp = [0] * (N + 1)
dp[1] = 1
for i in range(2, N + 1):
    for j in range(1, i):
        if abs(A[i] - A[j]) <= 3:
            dp[i] = max(dp[i], dp[j] + 1)

print(max(dp))
