def readInt():
    return int(input())
def readList():
    return list(map(int,input().split()))
def readMap():
	return map(int,input().split())
def readStr():
    return input()
inf=float('inf')
mod = 10**9+7
import math
from itertools import permutations
def solve(N,A,K):
    dp=[1]*N
    longest=0
    for i in range(N):
        for j in range(i):
            if abs(A[i]-A[j])<=3:
                dp[i]=max(dp[i],dp[j]+1)
                longest=max(longest,dp[i])
    return longest

N,K=readMap()
A=[]
for _ in range(N):
    A.append(readInt())
print(solve(N,A,K))