import sys
input = sys.stdin.readline
from collections import *

def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False

def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r

N = int(input())
S = input()[:-1]
print(binary_search()) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import * def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False judge d = defaultdict(int) d defaultdict(int) defaultdict int for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
     i range(N-x+1) range N-x+1 N-x N x 1 k = S[i:i+x] k S[i:i+x] S i:i+x i i+x i x if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
     k in d k d if i>=d[k]+x:
                return True
         i>=d[k]+x i d[k]+x d[k] d k x return True True d[k] = i d[k] d k i return False False x x def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r binary_search l, r = 0, N l 0 r N while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
     l<=r l r m = (l+r)//2 m (l+r)//2 l+r l r 2 if judge(m):
            l = m+1
        else:
            r = m-1
    
     judge(m) judge m l = m+1 l m+1 m 1 r = m-1 r m-1 m 1 return r r N = int(input()) N int(input()) int input() input S = input()[:-1] S input()[:-1] () input :-1 -1 print(binary_search()) print binary_search() binary_search def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r binary_search S = input()[:-1] input()[:-1] S N = int(input()) int(input()) N input = sys.stdin.readline sys.stdin.readline input def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False judge
import sys
input = sys.stdin.readline
from collections import *

def judge(x):
    d = defaultdict(int)
    
    for i in range(N-x+1):
        k = S[i:i+x]
        
        if k in d:
            if i>=d[k]+x:
                return True
        else:
            d[k] = i
    
    return False

def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r

N = int(input())
S = input()[:-1]
print(binary_search())
