import sys
from collections import Counter
read = sys.stdin.readline
N = int(read())
cat = read().strip()
L, R = 0, 0
cnt, ans = 1, 0
while L <= R < len(cat) - 1:
    if cat[R] == cat[R + 1] or cat[L] == cat[R + 1]:
        R += 1
    else:
        R += 1
        while len(Counter(cat[L:R + 1]).keys()) > N:
            L += 1
    ans = max(ans, R - L + 1)
print(ans)

297f5c3801d9d40bd0b11510be0d9695e3a51e92
<mask token>

<mask token>
while L <= R < len(cat) - 1:
    if cat[R] == cat[R + 1] or cat[L] == cat[R + 1]:
        R += 1
    else:
        R += 1
        while len(Counter(cat[L:R + 1]).keys()) > N:
            L += 1
    ans = max(ans, R - L + 1)
print(ans)

<mask token>
read = sys.stdin.readline
N = int(read())
cat = read().strip()
L, R = 0, 0
cnt, ans = 1, 0
while L <= R < len(cat) - 1:
    if cat[R] == cat[R + 1] or cat[L] == cat[R + 1]:
        R += 1
    else:
        R += 1
        while len(Counter(cat[L:R + 1]).keys()) > N:
            L += 1
    ans = max(ans, R - L + 1)
print(ans)

import sys
from collections import Counter
read = sys.stdin.readline
N = int(read())
cat = read().strip()
L, R = 0, 0
cnt, ans = 1, 0
while L <= R < len(cat) - 1:
    if cat[R] == cat[R + 1] or cat[L] == cat[R + 1]:
        R += 1
    else:
        R += 1
        while len(Counter(cat[L:R + 1]).keys()) > N:
            L += 1
    ans = max(ans, R - L + 1)
print(ans)
