n=int(input()) s = input() a=s[-1] for i in range(n): if s[i] == a: s1=s[i:] if s1 == s1[::-1]: print(i, end = '') break