def solve(n, s, d, MOD):

    ttt = [ord(c) - 97 for c in s]



    ttx = []

    c = 1

    for t in ttt[::-1]:

        ttx.append(t * c % MOD)

        c = c * d % MOD

    ttx.reverse()

    ttc = [0]

    for t in ttx:

        ttc.append((ttc[-1] + t) % MOD)



    l, r = 0, n

    while l < r:

        m = (l + r + 1) // 2

        if search(m, d, ttc, MOD):

            l = m

        else:

            r = m - 1



    return l





def search(w, d, ttc, MOD):

    appeared = []

    comparing = set()

    w2 = w * 2

    p = 1



    for i in range(w, n + 1):

        t = (ttc[i] - ttc[i - w]) * p % MOD

        if i >= w2:

            comparing.add(appeared[i - w2])

            if t in comparing:

                return True

        appeared.append(t)

        p = p * d % MOD



    return False





n = int(eval(input()))

s = eval(input())

MOD = 10 ** 9 + 7

print((min(solve(n, s, d, MOD) for d in (26, 29, 31))))

def solve(n, s, d, MOD):

    ttt = [ord(c) - 97 for c in s]



    ttx = []

    c = 1

    for t in ttt[::-1]:

        ttx.append(t * c % MOD)

        c = c * d % MOD

    ttx.reverse()

    ttc = [0]

    for t in ttx:

        ttc.append((ttc[-1] + t) % MOD)



    l, r = 0, n // 2 + 1

    while l < r:

        m = (l + r + 1) // 2

        if search(m, d, ttc, MOD):

            l = m

        else:

            r = m - 1



    return l





def search(w, d, ttc, MOD):

    appeared = []

    comparing = set()

    w2 = w * 2

    p = 1



    for i in range(w, n + 1):

        t = (ttc[i] - ttc[i - w]) * p % MOD

        if i >= w2:

            comparing.add(appeared[i - w2])

            if t in comparing:

                return True

        appeared.append(t)

        p = p * d % MOD



    return False





n = int(eval(input()))

s = eval(input())

MOD = 10 ** 9 + 7

print((min(solve(n, s, d, MOD) for d in (29, 31))))

def solve(n, s, d, MOD):
    ttt = [ord(c) - 97 for c in s]
    ttx = []
    c = 1
    for t in ttt[::-1]:
        ttx.append(t * c % MOD)
        c = c * d % MOD
    ttx.reverse()
    ttc = [0]
    for t in ttx:
        ttc.append((ttc[-1] + t) % MOD)
    l, r = 0, n
    while l < r:
        m = (l + r + 1) // 2
        if search(m, d, ttc, MOD):
            l = m
        else:
            r = m - 1
    return l


def search(w, d, ttc, MOD):
    appeared = []
    comparing = set()
    w2 = w * 2
    p = 1
    for i in range(w, n + 1):
        t = (ttc[i] - ttc[i - w]) * p % MOD
        if i >= w2:
            comparing.add(appeared[i - w2])
            if t in comparing:
                return True
        appeared.append(t)
        p = p * d % MOD
    return False


n = int(eval(input()))
s = eval(input())
MOD = 10**9 + 7
print((min(solve(n, s, d, MOD) for d in (26, 29, 31))))

def solve(n, s, d, MOD):
    ttt = [ord(c) - 97 for c in s]
    ttx = []
    c = 1
    for t in ttt[::-1]:
        ttx.append(t * c % MOD)
        c = c * d % MOD
    ttx.reverse()
    ttc = [0]
    for t in ttx:
        ttc.append((ttc[-1] + t) % MOD)
    l, r = 0, n // 2 + 1
    while l < r:
        m = (l + r + 1) // 2
        if search(m, d, ttc, MOD):
            l = m
        else:
            r = m - 1
    return l


def search(w, d, ttc, MOD):
    appeared = []
    comparing = set()
    w2 = w * 2
    p = 1
    for i in range(w, n + 1):
        t = (ttc[i] - ttc[i - w]) * p % MOD
        if i >= w2:
            comparing.add(appeared[i - w2])
            if t in comparing:
                return True
        appeared.append(t)
        p = p * d % MOD
    return False


n = int(eval(input()))
s = eval(input())
MOD = 10**9 + 7
print((min(solve(n, s, d, MOD) for d in (29, 31))))

-    l, r = 0, n +    l, r = 0, n // 2 + 1 -print((min(solve(n, s, d, MOD) for d in (26, 29, 31)))) +print((min(solve(n, s, d, MOD) for d in (29, 31))))