n = int(input())
s = input()
ans = 0
for i in range(n):
if 2 * (n - 1 - i) + 1 <= ans:
break
x = 0
while i - x >= 0 and i + x < n and s[i - x] == s[i + x]:
x += 1
ans = max(ans, 2 * x - 1)
for i in range(n):
if 2 * (n - 1 - i) <= ans:
break
x = 0
while i - x >= 0 and i + 1 + x < n and s[i - x] == s[i + 1 + x]:
x += 1
ans = max(ans, 2 * x)
print(ans)