import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()
for i in range(N):
    S[i] = ord(S[i])-97

# Rolling Hash

mod = 10**9+7
base = 1234


def f(n):  # 長さnで条件を満たす部分列が存在するか
    A = []
    a = 0
    for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
    A.append(a)
    for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
    for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
    return False


left = 0  # 可能
right = N+1  # 不可能
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid
print(left) import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 N = I() N I() I S = LS2() S LS2() LS2 for i in range(N):
    S[i] = ord(S[i])-97

# Rolling Hash i range(N) range N S[i] = ord(S[i])-97 S[i] S i ord(S[i])-97 ord(S[i]) ord S[i] S i 97 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 base = 1234 base 1234 def f(n):  # 長さnで条件を満たす部分列が存在するか
    A = []
    a = 0
    for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
    A.append(a)
    for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
    for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
    return False f A = [] A [] a = 0 a 0 for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
     i range(n) range n a += S[i]*pow(base,i,mod) a S[i]*pow(base,i,mod) S[i] S i pow(base,i,mod) pow base i mod a %= mod a mod A.append(a) A.append A append a for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
     i range(n,N) range n N a -= S[i-n] a S[i-n] S i-n i n a *= pow(base,mod-2,mod) a pow(base,mod-2,mod) pow base mod-2 mod 2 mod a %= mod a mod a += S[i]*pow(base,n-1,mod) a S[i]*pow(base,n-1,mod) S[i] S i pow(base,n-1,mod) pow base n-1 n 1 mod a %= mod a mod A.append(a) A.append A append a for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
     i range(N-n+1) range N-n+1 N-n N n 1 for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
     j range(i+n,N-n+1) range i+n i n N-n+1 N-n N n 1 if A[i] == A[j]:
                return True
     A[i] == A[j] A[i] A i A[j] A j return True True return False False n n left = 0 left 0 right = N+1 right N+1 N 1 while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid left + 1 < right left + 1 left 1 right mid = (left + right)//2 mid (left + right)//2 left + right left right 2 if f(mid):
        left = mid
    else:
        right = mid f(mid) f mid left = mid left mid right = mid right mid print(left) print left def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし LS2 N = I() I() N mod = 10**9+7 10**9+7 mod def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I S = LS2() LS2() S def f(n):  # 長さnで条件を満たす部分列が存在するか
    A = []
    a = 0
    for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
    A.append(a)
    for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
    for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
    return False def f(n):  # 長さnで条件を満たす部分列が存在するか
    A = []
    a = 0
    for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
    A.append(a)
    for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
    for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
    return False f right = mid mid right base = 1234 1234 base left = mid mid left left = 0 0 left right = N+1 N+1 right mid = (left + right)//2 (left + right)//2 mid
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
S = LS2()
for i in range(N):
    S[i] = ord(S[i])-97

# Rolling Hash

mod = 10**9+7
base = 1234


def f(n):  # 長さnで条件を満たす部分列が存在するか
    A = []
    a = 0
    for i in range(n):
        a += S[i]*pow(base,i,mod)
        a %= mod
    A.append(a)
    for i in range(n,N):
        a -= S[i-n]
        a *= pow(base,mod-2,mod)
        a %= mod
        a += S[i]*pow(base,n-1,mod)
        a %= mod
        A.append(a)
    for i in range(N-n+1):
        for j in range(i+n,N-n+1):
            if A[i] == A[j]:
                return True
    return False


left = 0  # 可能
right = N+1  # 不可能
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        left = mid
    else:
        right = mid
print(left)
