program ABC072C
    implicit none
    integer(8)::N,count,result,i
    integer(8)::flg=0
    integer(8)::p1=0
    integer(8),allocatable,dimension(:)::A
    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)
    A=iqsort(A)

    result=1
    count=0

    do i=2,N
        if(A(i)==A(i-1))then
            if(flg==0)then
                flg=1
                count=2
            else
                count=count+1
            end if
        else if(A(i)==A(i-1)+1.and.p1<=1)then
            p1=p1+1
            if(flg==0)then
                flg=1
                count=2
            else
                count=count+1
            end if
        else
            flg=0
            p1=0
            if(count>result)then
                result=count
            end if
        end if
    end do

    print'(i0)',result

contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC072C