def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

"""
Z algorithm
def Z(s):
    n = len(s)
    z = [0] * n
    z[0] = n

    L, R = 0, 0
    for i in range(1, n):
        if i >= R:
            L = R = i
            # 一致が続く限り伸ばす
            while(R < n and s[R - L] == s[R]):
                R += 1
            # LCAを書き込む
            # 頭から一致しない場合はR - L = i - i = 0
            z[i] = R - L
        # 全て利用できる場合
        elif z[i - L] < R - i:
            z[i] = z[i - L]
        # 一部利用できる場合
        else:
            L = i
            while(R < n and s[R - L] == s[R]):
                R += 1
            z[i] = R - L
    return z

# [5, 0, 3, 0, 1]
#print(Z('ababa'))

N = getN()
S = input()
ans = 0
for i in range(N):
    z = Z(S[i:])
    k = len(z)
    for j in range(k):
        # '' と 'ababa'
        # 'a' と 'baba'
        # 'ab' と 'aba'
        # ans は j('', 'a', 'ab')の長さ以上にならない（ダブらないため）
        ans = max(ans, min(j, z[j]))
print(ans)
"""

# Rolling hash
N = getN()
S = list(map(ord, list(input())))
# 適当
base = 1234
power = [1] * (N + 1)
# 部分文字列を数字に
for i in range(1, N + 1):
    power[i] = power[i - 1] * base % mod

def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = {res: 0}
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2

    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok) def getN():
    return int(input()) getN return int(input()) int(input()) int input() input def getNM():
    return map(int, input().split()) getNM return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def getList():
    return list(map(int, input().split())) getList return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def getArray(intn):
    return [int(input()) for i in range(intn)] getArray int(input()) for i in range(intn) for i in range(intn) i range(intn) range intn for i in range(intn) int(input()) int input() input return [int(input()) for i in range(intn)] [int(input()) for i in range(intn)] intn intn def input():
    return sys.stdin.readline().rstrip() input return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N return random.randint(ran1, ran2) random.randint(ran1, ran2) random.randint random randint ran1 ran2 ran1 ran1 ran2 ran2 def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List random.randint(ran1, ran2) for i in range(rantime) for i in range(rantime) i range(rantime) range rantime for i in range(rantime) random.randint(ran1, ran2) random.randint random randint ran1 ran2 return [random.randint(ran1, ran2) for i in range(rantime)] [random.randint(ran1, ran2) for i in range(rantime)] ran1 ran1 ran2 ran2 rantime rantime def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup ns = [] ns [] while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
   len(ns) < rantime len(ns) len ns rantime n = random.randint(ran1, ran2) n random.randint(ran1, ran2) random.randint random randint ran1 ran2 if not n in ns:
      ns.append(n)
   not n in ns n in ns n ns ns.append(n) ns.append ns append n return sorted(ns) sorted(ns) sorted ns ran1 ran1 ran2 ran2 rantime rantime def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query r_query = [] r_query [] while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
   len(r_query) < rantime len(r_query) len r_query rantime n_q = rand_ints_nodup(ran1, ran2, 2) n_q rand_ints_nodup(ran1, ran2, 2) rand_ints_nodup ran1 ran2 2 if not n_q in r_query:
      r_query.append(n_q)
   not n_q in r_query n_q in r_query n_q r_query r_query.append(n_q) r_query.append r_query append n_q return sorted(r_query) sorted(r_query) sorted r_query ran1 ran1 ran2 ran2 rantime rantime from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq heapq import math math from fractions import gcd import random random import string string import copy copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys sys.setrecursionlimit(1000000000) sys.setrecursionlimit sys setrecursionlimit 1000000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 """
Z algorithm
def Z(s):
    n = len(s)
    z = [0] * n
    z[0] = n

    L, R = 0, 0
    for i in range(1, n):
        if i >= R:
            L = R = i
            # 一致が続く限り伸ばす
            while(R < n and s[R - L] == s[R]):
                R += 1
            # LCAを書き込む
            # 頭から一致しない場合はR - L = i - i = 0
            z[i] = R - L
        # 全て利用できる場合
        elif z[i - L] < R - i:
            z[i] = z[i - L]
        # 一部利用できる場合
        else:
            L = i
            while(R < n and s[R - L] == s[R]):
                R += 1
            z[i] = R - L
    return z

# [5, 0, 3, 0, 1]
#print(Z('ababa'))

N = getN()
S = input()
ans = 0
for i in range(N):
    z = Z(S[i:])
    k = len(z)
    for j in range(k):
        # '' と 'ababa'
        # 'a' と 'baba'
        # 'ab' と 'aba'
        # ans は j('', 'a', 'ab')の長さ以上にならない（ダブらないため）
        ans = max(ans, min(j, z[j]))
print(ans)
""" N = getN() N getN() getN S = list(map(ord, list(input()))) S list(map(ord, list(input()))) list map(ord, list(input())) map ord list(input()) list input() input base = 1234 base 1234 power = [1] * (N + 1) power [1] * (N + 1) [1] 1 N + 1 N 1 for i in range(1, N + 1):
    power[i] = power[i - 1] * base % mod i range(1, N + 1) range 1 N + 1 N 1 power[i] = power[i - 1] * base % mod power[i] power i power[i - 1] * base % mod power[i - 1] * base power[i - 1] power i - 1 i 1 base mod def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = {res: 0}
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False check if N - m < m:
        return False
     N - m < m N - m N m m return False False res = 0 res 0 for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
     i range(m) range m res += S[i] * power[m - i - 1] res S[i] * power[m - i - 1] S[i] S i power[m - i - 1] power m - i - 1 m - i m i 1 res %= mod res mod dic = {res: 0} dic {res: 0} res res 0 for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
     i range(N - m) range N - m N m res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod res ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod (res - S[i] * power[m - 1]) * base + S[i + m] (res - S[i] * power[m - 1]) * base res - S[i] * power[m - 1] res S[i] * power[m - 1] S[i] S i power[m - 1] power m - 1 m 1 base S[i + m] S i + m i m mod if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
     res in dic.keys() res dic.keys() dic.keys dic keys index = dic[res] index dic[res] dic res if index + m <= i + 1:
                return True
         index + m <= i + 1 index + m index m i + 1 i 1 return True True dic[res] = i + 1 dic[res] dic res i + 1 i 1 return False False m m ok = 0 ok 0 ng = N + 1 ng N + 1 N 1 while ng - ok > 1:
    mid = (ok + ng) // 2

    if check(mid):
        ok = mid
    else:
        ng = mid ng - ok > 1 ng - ok ng ok 1 mid = (ok + ng) // 2 mid (ok + ng) // 2 ok + ng ok ng 2 if check(mid):
        ok = mid
    else:
        ng = mid check(mid) check mid ok = mid ok mid ng = mid ng mid print(ok) print ok ok = mid mid ok def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N def getList():
    return list(map(int, input().split())) def getList():
    return list(map(int, input().split())) getList power = [1] * (N + 1) [1] * (N + 1) power ng = N + 1 N + 1 ng mod = 10 ** 9 + 7 10 ** 9 + 7 mod def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = {res: 0}
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = {res: 0}
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False check ng = mid mid ng def getNM():
    return map(int, input().split()) def getNM():
    return map(int, input().split()) getNM def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup def getN():
    return int(input()) def getN():
    return int(input()) getN def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List N = getN() getN() N base = 1234 1234 base def getArray(intn):
    return [int(input()) for i in range(intn)] def getArray(intn):
    return [int(input()) for i in range(intn)] getArray ok = 0 0 ok mid = (ok + ng) // 2 (ok + ng) // 2 mid S = list(map(ord, list(input()))) list(map(ord, list(input()))) S
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

"""
Z algorithm
def Z(s):
    n = len(s)
    z = [0] * n
    z[0] = n

    L, R = 0, 0
    for i in range(1, n):
        if i >= R:
            L = R = i
            # 一致が続く限り伸ばす
            while(R < n and s[R - L] == s[R]):
                R += 1
            # LCAを書き込む
            # 頭から一致しない場合はR - L = i - i = 0
            z[i] = R - L
        # 全て利用できる場合
        elif z[i - L] < R - i:
            z[i] = z[i - L]
        # 一部利用できる場合
        else:
            L = i
            while(R < n and s[R - L] == s[R]):
                R += 1
            z[i] = R - L
    return z

# [5, 0, 3, 0, 1]
#print(Z('ababa'))

N = getN()
S = input()
ans = 0
for i in range(N):
    z = Z(S[i:])
    k = len(z)
    for j in range(k):
        # '' と 'ababa'
        # 'a' と 'baba'
        # 'ab' と 'aba'
        # ans は j('', 'a', 'ab')の長さ以上にならない（ダブらないため）
        ans = max(ans, min(j, z[j]))
print(ans)
"""

# Rolling hash
N = getN()
S = list(map(ord, list(input())))
# 適当
base = 1234
power = [1] * (N + 1)
# 部分文字列を数字に
for i in range(1, N + 1):
    power[i] = power[i - 1] * base % mod

def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = {res: 0}
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if res in dic.keys():
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False

ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2

    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)