implicit none
integer :: n
integer, allocatable :: a(:)
integer :: i,j,k,maxk
logical :: flg

read *,n
allocate(a(n))
read *,(a(i),i=1,n)

i = n
flg = .false.
do while (i > 1 .or. flg)
   i = (i * 10) / 13
   if (i < 1) then
      i = 1
   else if (i == 9 .or. i == 10) then 
      i = 11
   endif
   flg = .false.
   do j = 1, n-i
      if (a(j) > a(j+i)) then
         k = a(j) 
         a(j) = a(j+i)
         a(j+i) = k
         flg = .true.
      endif
   enddo
enddo

i = 1
j = 1
maxk = 1
do while (j < n)
   do while (a(j) - a(i) <= 2 .and. j <= n)
      j = j + 1
   enddo
   k = j - i
   if (k > maxk) then
      maxk = k
   endif
   do while (a(j) - a(i) > 2 .and. i < j)
      i = i + 1
   enddo
enddo

print '(i0)',maxk
end