integer N
character(5000) S
integer maxlen
integer ans
read*,N
read*,S
ans=0
do i=1,N-1
  do j=i+1,N
    if(S(i:i)==S(j:j))then
      maxlen=min(N-j+1,j-i)
      if(maxlen<=ans)cycle
      do ii=maxlen,1,-1
        if(S(i:i+ii-1)==S(J:J+ii-1))then
          ans=max(ans,ii)
          exit
        endif
      end do
    endif
  end do
end do
print"(I0)",ans
end