'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma

def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None

if __name__ == '__main__':
    main() '''
自宅用PCでの解答
''' import math math import itertools itertools import queue queue import bisect bisect from collections import deque,defaultdict import heapq as hpq heapq from sys import stdin,setrecursionlimit ipt = stdin.readline ipt stdin.readline stdin readline setrecursionlimit(10**7) setrecursionlimit 10**7 10 7 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 dir = [(-1,0),(0,-1),(1,0),(0,1)] dir [(-1,0),(0,-1),(1,0),(0,1)] (-1,0) -1 0 (0,-1) 0 -1 (1,0) 1 0 (0,1) 0 1 alp = "abcdefghijklmnopqrstuvwxyz" alp "abcdefghijklmnopqrstuvwxyz" def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma z_algorithm ma = 0 ma 0 prefix = [0]*len(s) prefix [0]*len(s) [0] 0 len(s) len s j = 0 j 0 for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
     i range(1,len(s)) range 1 len(s) len s if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
     i+prefix[i-j] < j+prefix[j] i+prefix[i-j] i prefix[i-j] prefix i-j i j j+prefix[j] j prefix[j] prefix j prefix[i] = prefix[i-j] prefix[i] prefix i prefix[i-j] prefix i-j i j k = max(0,j+prefix[j]-i) k max(0,j+prefix[j]-i) max 0 j+prefix[j]-i j+prefix[j] j prefix[j] prefix j i while i+k < len(s) and s[k] == s[i+k]:
                k += 1
             i+k < len(s) and s[k] == s[i+k] i+k < len(s) i+k i k len(s) len s s[k] == s[i+k] s[k] s k s[i+k] s i+k i k k += 1 k 1 prefix[i] = k prefix[i] prefix i k j = i j i prefix[0] = len(s) prefix[0] prefix 0 len(s) len s for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
     i pi enumerate(prefix) enumerate prefix if i < pi:
            prefix[i] = i
     i < pi i pi prefix[i] = i prefix[i] prefix i i for i in prefix:
        if ma < i:
            ma = i
     i prefix if ma < i:
            ma = i
     ma < i ma i ma = i ma i return ma ma s s def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None main n = int(ipt()) n int(ipt()) int ipt() ipt s = input() s input() input ma = 0 ma 0 for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

     i range(n) range n pf = z_algorithm(s[i::]) pf z_algorithm(s[i::]) z_algorithm s[i::] s i:: i if ma < pf:
            ma = pf

     ma < pf ma pf ma = pf ma pf print(ma) print ma return None None if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None main mod = 10**9+7 10**9+7 mod ipt = stdin.readline stdin.readline ipt dir = [(-1,0),(0,-1),(1,0),(0,1)] [(-1,0),(0,-1),(1,0),(0,1)] dir def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma z_algorithm alp = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alp
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def z_algorithm(s):
    ma = 0
    prefix = [0]*len(s)
    j = 0
    for i in range(1,len(s)):
        if i+prefix[i-j] < j+prefix[j]:
            prefix[i] = prefix[i-j]
        else:
            k = max(0,j+prefix[j]-i)
            while i+k < len(s) and s[k] == s[i+k]:
                k += 1
            prefix[i] = k
            j = i
    prefix[0] = len(s)
    for i,pi in enumerate(prefix):
        if i < pi:
            prefix[i] = i
    for i in prefix:
        if ma < i:
            ma = i
    return ma

def main():
    n = int(ipt())
    s = input()
    ma = 0
    for i in range(n):
        pf = z_algorithm(s[i::])
        if ma < pf:
            ma = pf

    print(ma)

    return None

if __name__ == '__main__':
    main()
