n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
maxa=max(a)
dp=[0]*(maxa+1)
for x in a:
  tmp=0
  for i in range(3):
    if 0<=x-i-1:tmp=max(tmp,dp[x-i-1])
    if x+i+1<=maxa:tmp=max(tmp,dp[x+i+1])
  dp[x]=tmp+1
print(max(dp))