import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer) import sys sys N=int(input()) N int(input()) int input() input S=input() S input() input def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z z_alg N=len(S) N len(S) len S Z=[N]+[0]*(N-1) Z [N]+[0]*(N-1) [N] N [0]*(N-1) [0] 0 N-1 N 1 i,j=1,0 i 1 j 0 while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
   i<N i N while i+j<N and S[j]==S[i+j]:
      j+=1
     i+j<N and S[j]==S[i+j] i+j<N i+j i j N S[j]==S[i+j] S[j] S j S[i+j] S i+j i j j+=1 j 1 if not j:
      i+=1
      continue
     not j j i+=1 i 1 continue Z[i]=j Z[i] Z i j k=1 k 1 while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
     N-i>k and k<j-Z[k] N-i>k N-i N i k k<j-Z[k] k j-Z[k] j Z[k] Z k Z[i+k]=Z[k] Z[i+k] Z i+k i k Z[k] Z k k+=1 k 1 i+=k i k j-=k j k return Z Z S S answer=0 answer 0 for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
       i range(N) range N zlist=z_alg(S[i:]) zlist z_alg(S[i:]) z_alg S[i:] S i: i for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
       j range(N-i) range N-i N i if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
       j>=zlist[j] and answer<zlist[j] j>=zlist[j] j zlist[j] zlist j answer<zlist[j] answer zlist[j] zlist j answer=zlist[j] answer zlist[j] zlist j print(answer) print answer answer=0 0 answer answer=zlist[j] zlist[j] answer def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z z_alg S=input() input() S N=int(input()) int(input()) N zlist=z_alg(S[i:]) z_alg(S[i:]) zlist
import sys
N=int(input())
S=input()

def z_alg(S):
  N=len(S)
  Z=[N]+[0]*(N-1)
  i,j=1,0
  while i<N:
    while i+j<N and S[j]==S[i+j]:
      j+=1
    if not j:
      i+=1
      continue
    Z[i]=j
    k=1
    while N-i>k and k<j-Z[k]:
      Z[i+k]=Z[k]
      k+=1
    i+=k
    j-=k
  return Z

answer=0
for i in range(N):
  zlist=z_alg(S[i:])
  #print(i,S[i:],zlist)
  for j in range(N-i):
    if j>=zlist[j] and answer<zlist[j]:
      answer=zlist[j]
      
print(answer)