integer N
character(5000) S
integer maxlen
integer ans,preans
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
      preans=1
      do ii=1,maxlen-1
        if(S(i+ii:i+ii)/=S(j+ii:j+ii))exit
        preans=preans+1
      end do
      ans=max(ans,preans)
    endif
  end do
end do
print"(I0)",ans
end