import bisect
N,K=map(int,input().split())
A=int(input())
LIS = [A]
for i in range(N-1):
  A=int(input())
  if abs(A-LIS[-1])<=3:
    LIS.append(A)
  else:
    LIS[bisect.bisect_left(LIS, A)-1] = A

print(len(LIS))