import math
n, k = map(int, input().split())
A = []
A_pre = []
for i in range(n):
  a = int(input())
  A.append(a)
  if i == 0:
    A_pre.append(a)
  else:
    if abs(A_pre[-1] - a) <= 3:
      A_pre.append(a)
A_pre = len(A_pre)
      
A_suf = []
for i, a in enumerate(A[::-1]):
  if i == 0:
    A_suf.append(a)
  else:
    if abs(A_suf[-1] - a) <= 3:
      A_suf.append(a)
A_suf = len(A_suf)

print(max(A_pre, A_suf))
