n = int(input())
s = input()

A = 1234567
MOD = 10000000000000007

def ok(length):
    rolling_hash = 0
    head = pow(A, length, MOD)
    occurence = {}
    for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

    for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
    return False

bottom, top = 0, n

while top - bottom > 1:
    mid = (top + bottom) // 2
    if ok(mid):bottom = mid
    else: top = mid

print(bottom) n = int(input()) n int(input()) int input() input s = input() s input() input A = 1234567 A 1234567 MOD = 10000000000000007 MOD 10000000000000007 def ok(length):
    rolling_hash = 0
    head = pow(A, length, MOD)
    occurence = {}
    for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

    for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
    return False ok rolling_hash = 0 rolling_hash 0 head = pow(A, length, MOD) head pow(A, length, MOD) pow A length MOD occurence = {} occurence {} for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

     i range(n) range n rolling_hash = (rolling_hash * A + ord(s[i])) % MOD rolling_hash (rolling_hash * A + ord(s[i])) % MOD rolling_hash * A + ord(s[i]) rolling_hash * A rolling_hash A ord(s[i]) ord s[i] s i MOD if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
         i - length >= 0 i - length i length 0 rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD rolling_hash (rolling_hash - head * ord(s[i-length])) % MOD rolling_hash - head * ord(s[i-length]) rolling_hash head * ord(s[i-length]) head ord(s[i-length]) ord s[i-length] s i-length i length MOD if rolling_hash not in occurence:
            occurence[rolling_hash] = []
         rolling_hash not in occurence rolling_hash occurence occurence[rolling_hash] = [] occurence[rolling_hash] occurence rolling_hash [] occurence[rolling_hash].append(i) [rolling_hash].append [rolling_hash] occurence rolling_hash append i for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
     key occurence if occurence[key][-1] - occurence[key][0] >= length:
            return True
     occurence[key][-1] - occurence[key][0] >= length occurence[key][-1] - occurence[key][0] occurence[key][-1] [key] occurence key -1 occurence[key][0] [key] occurence key 0 length return True True return False False length length bottom, top = 0, n bottom 0 top n while top - bottom > 1:
    mid = (top + bottom) // 2
    if ok(mid):bottom = mid
    else: top = mid top - bottom > 1 top - bottom top bottom 1 mid = (top + bottom) // 2 mid (top + bottom) // 2 top + bottom top bottom 2 if ok(mid):bottom = mid
    else: top = mid ok(mid) ok mid print(bottom) print bottom mid = (top + bottom) // 2 (top + bottom) // 2 mid n = int(input()) int(input()) n s = input() input() s bottom, top = 0, n 0 bottom top = 0, n n top MOD = 10000000000000007 10000000000000007 MOD A = 1234567 1234567 A def ok(length):
    rolling_hash = 0
    head = pow(A, length, MOD)
    occurence = {}
    for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

    for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
    return False def ok(length):
    rolling_hash = 0
    head = pow(A, length, MOD)
    occurence = {}
    for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

    for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
    return False ok
n = int(input())
s = input()

A = 1234567
MOD = 10000000000000007

def ok(length):
    rolling_hash = 0
    head = pow(A, length, MOD)
    occurence = {}
    for i in range(n):
        rolling_hash = (rolling_hash * A + ord(s[i])) % MOD
        if i - length >= 0:
            rolling_hash = (rolling_hash - head * ord(s[i-length])) % MOD
        if rolling_hash not in occurence:
            occurence[rolling_hash] = []
        occurence[rolling_hash].append(i)

    for key in occurence:
        if occurence[key][-1] - occurence[key][0] >= length:
            return True
    return False

bottom, top = 0, n

while top - bottom > 1:
    mid = (top + bottom) // 2
    if ok(mid):bottom = mid
    else: top = mid

print(bottom)