def reverse(s,k):
    mark = 0
    count = k
    for i in range(len(s)//2):
        count1=i
        if i!=0 and mark == 0 and s[i]==s[-1]:
            count = i
            mark = 1
        if s[i]!=s[len(s)-i-1]:
            if mark == 1:
                return False,count
            else:
                return False, count1
    return True,count



n=int(input())
s = input()

a=s[-1]
i = 0
while i<n:
    if s[i] == a:
        s1=s[i:]
        y = reverse(s1,i)
        if y[0]:
            print(i, end = '')
            break
        i += y[1]

    else:
        i+=1




