integer N
character(5000) S

integer,allocatable,dimension(:)::seen1,seen2,seen3
integer mod1,mod2,mod3
integer base1,base2,base3
integer(16) rh1,rh2,rh3
integer,allocatable,dimension(:)::pow1,pow2,pow3

integer ok,ng,md
logical mdcheck

integer i

read*,N
read*,S
mod1=30203
mod2=30211
mod3=6871
allocate(seen1(0:mod1-1),seen2(0:mod2-1),seen3(0:mod3-1))
base1=353
base2=359
base3=139
allocate(pow1(0:N),pow2(0:N),pow3(0:N))
pow1(0)=1;pow2(0)=1;pow3(0)=1
do i=1,N
  pow1(i)=mod(pow1(i-1)*base1,mod1)
  pow2(i)=mod(pow2(i-1)*base2,mod2)
  pow3(i)=mod(pow3(i-1)*base3,mod3)
end do

ok=0;ng=N/2+1
md=(ok+ng)/2
do while(ng-ok>1)
  mdcheck=.false.
  
  seen1=-1;seen2=-1;seen3=-1
  rh1=0;rh2=0;rh3=0
  do i=1,md
    rh1=mod(rh1+ichar(S(i:i))*pow1(md-i),mod1)
    rh2=mod(rh2+ichar(S(i:i))*pow2(md-i),mod2)
    rh3=mod(rh3+ichar(S(i:i))*pow3(md-i),mod3)
  end do
  seen1(rh1)=1;seen2(rh2)=1;seen3(rh3)=1
  do i=2,N-md+1
    rh1=mod(mod(rh1*base1,mod1)+ichar(S(i+md-1:i+md-1))-mod(ichar(S(i-1:i-1))*pow1(md),mod1),mod1)
    rh2=mod(mod(rh2*base2,mod2)+ichar(S(i+md-1:i+md-1))-mod(ichar(S(i-1:i-1))*pow2(md),mod2),mod2)
    rh3=mod(mod(rh3*base3,mod3)+ichar(S(i+md-1:i+md-1))-mod(ichar(S(i-1:i-1))*pow3(md),mod3),mod3)
	if(rh1<0)rh1=rh1+mod1
    if(rh2<0)rh2=rh2+mod2
    if(rh3<0)rh3=rh3+mod3
    if(seen1(rh1)>0 .and. seen2(rh2)>0 .and. seen3(rh3)>0 )then
      if(i-seen1(rh1)>=md .and. i-seen2(rh2)>=md.and.i-seen3(rh3)>=md)then
        mdcheck=.true.
        exit
      endif
    else
      if(seen1(rh1)<0)seen1(rh1)=i
      if(seen2(rh2)<0)seen2(rh2)=i
      if(seen3(rh3)<0)seen3(rh3)=i
    endif
  end do
  if(mdcheck)then
    ok=md
  else
    ng=md
  endif
  md=(ok+ng)/2
end do

print"(I0)",ok
end