from collections import deque

class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2)


n = int(input())
s = input()
rh = RollingHash(s)

for len_ in range(n//2,0,-1):
    ql = [(-1,-1)]*(len_-1)
    wait_q = deque(ql)
    hset = set()
    # print(len_)
    for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset)

else:
    print(0) from collections import deque class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2) RollingHash def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

     __init__ self.mod1 = mod1 self.mod1 self mod1 mod1 self.mod2 = mod2 self.mod2 self mod2 mod2 self.s = s self.s self s s n = len(s) n len(s) len s self.hash1 = [0]*(n+1) self.hash1 self hash1 [0]*(n+1) [0] 0 n+1 n 1 self.pow1 = [1]*(n+1) self.pow1 self pow1 [1]*(n+1) [1] 1 n+1 n 1 self.hash2 = [0]*(n+1) self.hash2 self hash2 [0]*(n+1) [0] 0 n+1 n 1 self.pow2 = [1]*(n+1) self.pow2 self pow2 [1]*(n+1) [1] 1 n+1 n 1 for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

     i range(n) range n self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1 self.hash1[i+1] self.hash1 self hash1 i+1 i 1 (self.hash1[i]*base1 + ord(s[i])) % self.mod1 self.hash1[i]*base1 + ord(s[i]) self.hash1[i]*base1 self.hash1[i] self.hash1 self hash1 i base1 ord(s[i]) ord s[i] s i self.mod1 self mod1 self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1 self.pow1[i+1] self.pow1 self pow1 i+1 i 1 (self.pow1[i]*base1) % self.mod1 self.pow1[i]*base1 self.pow1[i] self.pow1 self pow1 i base1 self.mod1 self mod1 self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2 self.hash2[i+1] self.hash2 self hash2 i+1 i 1 (self.hash2[i]*base2 + ord(s[i])) % self.mod2 self.hash2[i]*base2 + ord(s[i]) self.hash2[i]*base2 self.hash2[i] self.hash2 self hash2 i base2 ord(s[i]) ord s[i] s i self.mod2 self mod2 self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2 self.pow2[i+1] self.pow2 self pow2 i+1 i 1 (self.pow2[i]*base2) % self.mod2 self.pow2[i]*base2 self.pow2[i] self.pow2 self pow2 i base2 self.mod2 self mod2 self self s s base1=1007 base1 1007 base2=2009 base2 2009 mod1=10**9+7 mod1 10**9+7 10**9 10 9 7 mod2=10**9+9 mod2 10**9+9 10**9 10 9 9 def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2) get h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1 h1 (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1 self.hash1[r] - self.hash1[l] * self.pow1[r-l] self.hash1[r] self.hash1 self hash1 r self.hash1[l] * self.pow1[r-l] self.hash1[l] self.hash1 self hash1 l self.pow1[r-l] self.pow1 self pow1 r-l r l self.mod1 self mod1 h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2 h2 (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2 self.hash2[r] - self.hash2[l] * self.pow2[r-l] self.hash2[r] self.hash2 self hash2 r self.hash2[l] * self.pow2[r-l] self.hash2[l] self.hash2 self hash2 l self.pow2[r-l] self.pow2 self pow2 r-l r l self.mod2 self mod2 return (h1,h2) (h1,h2) h1 h2 self self l l r r n = int(input()) n int(input()) int input() input s = input() s input() input rh = RollingHash(s) rh RollingHash(s) RollingHash s for len_ in range(n//2,0,-1):
    ql = [(-1,-1)]*(len_-1)
    wait_q = deque(ql)
    hset = set()
    # print(len_)
    for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset)

else:
    print(0) len_ range(n//2,0,-1) range n//2 n 2 0 -1 ql = [(-1,-1)]*(len_-1) ql [(-1,-1)]*(len_-1) [(-1,-1)] (-1,-1) -1 -1 len_-1 len_ 1 wait_q = deque(ql) wait_q deque(ql) deque ql hset = set() hset set() set for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset) i range(n-len_+1) range n-len_+1 n-len_ n len_ 1 hs = rh.get(i,i+len_) hs rh.get(i,i+len_) rh.get rh get i i+len_ i len_ if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset) hs in hset hs hset print(len_) print len_ exit() exit wait_q.append(hs) wait_q.append wait_q append hs hset.add(wait_q.popleft()) hset.add hset add wait_q.popleft() wait_q.popleft wait_q popleft print(0) print 0 wait_q = deque(ql) deque(ql) wait_q s = input() input() s hs = rh.get(i,i+len_) rh.get(i,i+len_) hs class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2) class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2) RollingHash hset = set() set() hset ql = [(-1,-1)]*(len_-1) [(-1,-1)]*(len_-1) ql rh = RollingHash(s) RollingHash(s) rh n = int(input()) int(input()) n
from collections import deque

class RollingHash():
    def __init__(self, s, base1=1007, base2=2009, mod1=10**9+7, mod2=10**9+9):
        self.mod1 = mod1
        self.mod2 = mod2
        self.s = s
        n = len(s)
        self.hash1 = [0]*(n+1)
        self.pow1 = [1]*(n+1)
        self.hash2 = [0]*(n+1)
        self.pow2 = [1]*(n+1)
        for i in range(n):
            self.hash1[i+1] = (self.hash1[i]*base1 + ord(s[i])) % self.mod1
            self.pow1[i+1] = (self.pow1[i]*base1) % self.mod1
            self.hash2[i+1] = (self.hash2[i]*base2 + ord(s[i])) % self.mod2
            self.pow2[i+1] = (self.pow2[i]*base2) % self.mod2

    def get(self, l, r):
        h1 = (self.hash1[r] - self.hash1[l] * self.pow1[r-l]) % self.mod1
        h2 = (self.hash2[r] - self.hash2[l] * self.pow2[r-l]) % self.mod2
        return (h1,h2)


n = int(input())
s = input()
rh = RollingHash(s)

for len_ in range(n//2,0,-1):
    ql = [(-1,-1)]*(len_-1)
    wait_q = deque(ql)
    hset = set()
    # print(len_)
    for i in range(n-len_+1):
        # print(s[i:i+len_])
        hs = rh.get(i,i+len_)
        if hs in hset:
            print(len_)
            exit()
        else:
            wait_q.append(hs)
            hset.add(wait_q.popleft())
        # print(wait_q)
        # print(hset)

else:
    print(0)