import random
from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
mod = (1<<61)-1
base = 1000+random.randint(0,100)
power = [1]
for i in range(1,n):
  power.append((power[-1]*base)%mod)
hvalue = [0]
for i in range(n):
  hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod)
def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod
def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False
l=0
r=n//2+1
while l+1<r:
  mi=(l+r)//2
  if pun(mi):
    l=mi
  else:
    r=mi
print(l) import random random from collections import defaultdict from itertools import accumulate import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input s = input().rstrip() s input().rstrip() ().rstrip () input rstrip mod = (1<<61)-1 mod (1<<61)-1 1<<61 1 61 1 base = 1000+random.randint(0,100) base 1000+random.randint(0,100) 1000 random.randint(0,100) random.randint random randint 0 100 power = [1] power [1] 1 for i in range(1,n):
  power.append((power[-1]*base)%mod) i range(1,n) range 1 n power.append((power[-1]*base)%mod) power.append power append (power[-1]*base)%mod power[-1]*base power[-1] power -1 base mod hvalue = [0] hvalue [0] 0 for i in range(n):
  hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod) i range(n) range n hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod) hvalue.append hvalue append (hvalue[-1]+(ord(s[i])*power[i]))%mod hvalue[-1]+(ord(s[i])*power[i]) hvalue[-1] hvalue -1 ord(s[i])*power[i] ord(s[i]) ord s[i] s i power[i] power i mod def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod rollinghash return ((hvalue[r]-hvalue[l])*power[n-r])%mod ((hvalue[r]-hvalue[l])*power[n-r])%mod (hvalue[r]-hvalue[l])*power[n-r] hvalue[r]-hvalue[l] hvalue[r] hvalue r hvalue[l] hvalue l power[n-r] power n-r n r mod l l r r def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False pun dc = defaultdict(int) dc defaultdict(int) defaultdict int if i>n//2:
    return False
   i>n//2 i n//2 n 2 return False False for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
   j range(n-i+1) range n-i+1 n-i n i 1 x = rollinghash(j,i+j) x rollinghash(j,i+j) rollinghash j i+j i j if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
   dc[x] dc x rg =dc[x] rg dc[x] dc x if rg<=j:
        return True
     rg<=j rg j return True True dc[x] = i+j dc[x] dc x i+j i j return False False i i l=0 l 0 r=n//2+1 r n//2+1 n//2 n 2 1 while l+1<r:
  mi=(l+r)//2
  if pun(mi):
    l=mi
  else:
    r=mi l+1<r l+1 l 1 r mi=(l+r)//2 mi (l+r)//2 l+r l r 2 if pun(mi):
    l=mi
  else:
    r=mi pun(mi) pun mi l=mi l mi r=mi r mi print(l) print l n = int(input()) int(input()) n r=mi mi r power = [1] [1] power mod = (1<<61)-1 (1<<61)-1 mod def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False pun mi=(l+r)//2 (l+r)//2 mi s = input().rstrip() input().rstrip() s r=n//2+1 n//2+1 r l=mi mi l input = sys.stdin.readline sys.stdin.readline input hvalue = [0] [0] hvalue def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod rollinghash base = 1000+random.randint(0,100) 1000+random.randint(0,100) base l=0 0 l
import random
from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
mod = (1<<61)-1
base = 1000+random.randint(0,100)
power = [1]
for i in range(1,n):
  power.append((power[-1]*base)%mod)
hvalue = [0]
for i in range(n):
  hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))%mod)
def rollinghash(l,r):
  return ((hvalue[r]-hvalue[l])*power[n-r])%mod
def pun(i):
  dc = defaultdict(int)
  if i>n//2:
    return False
  for j in range(n-i+1):
    x = rollinghash(j,i+j)
    if dc[x]:
      rg =dc[x]
      if rg<=j:
        return True
    else:
      dc[x] = i+j
  return False
l=0
r=n//2+1
while l+1<r:
  mi=(l+r)//2
  if pun(mi):
    l=mi
  else:
    r=mi
print(l)
