Ilya lives in a beautiful city of Chordalsk.

There are n houses on the street Ilya lives, they are numerated from 1 to n from left to right; the distance between every two neighboring houses is equal to 1 unit. The neighboring houses are 1 and 2, 2 and 3, ..., n-1 and n. The houses n and 1 are not neighboring.

The houses are colored in colors c_1, c_2, …, c_n so that the i-th house is colored in the color c_i. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.

Ilya wants to select two houses i and j so that 1 ≤ i < j ≤ n, and they have different colors: c_i ≠ c_j. He will then walk from the house i to the house j the distance of (j-i) units.

Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.

Help Ilya, find this maximum possible distance.

Input

The first line contains a single integer n (3 ≤ n ≤ 300 000) — the number of cities on the street.

The second line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ n) — the colors of the houses.

It is guaranteed that there is at least one pair of indices i and j so that 1 ≤ i < j ≤ n and c_i ≠ c_j.

Output

Print a single integer — the maximum possible distance Ilya can walk.

Examples

Input


5
1 2 3 2 3


Output


4


Input


3
1 2 1


Output


1


Input


7
1 1 3 1 1 1 1


Output


4

Note

In the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of 5-1 = 4 units.

In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of 1 unit.

In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of 7-3 = 4 units. 
from __future__ import division, print_function
py2 = round(0.5)

if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

def sync_with_stdio(b):
    if b: return
    import os, sys
    from io import BytesIO, IOBase
    
    # FastIO for PyPy2 and PyPy3 (works with interactive) by Pajenegod
    class FastI(object):
        def __init__(self, fd=0, buffersize=2**14):
            self.stream = stream = BytesIO(); self.bufendl = 0
            def read2buffer():
                s = os.read(fd, buffersize + os.fstat(fd).st_size); pos = stream.tell()
                stream.seek(0,2); stream.write(s); stream.seek(pos); return s
            self.read2buffer = read2buffer
        # Read entire input
        def read(self):
            while self.read2buffer(): pass
            return self.stream.read() if self.stream.tell() else self.stream.getvalue()
        def readline(self):
            while self.bufendl == 0: s = self.read2buffer(); self.bufendl += s.count(b'\n') + (not s)
            self.bufendl -= 1; return self.stream.readline()
        def input(self): return self.readline().rstrip(b'\r\n')
        
        # Read all remaining integers, type is given by optional argument
        def readnumbers(self, zero=0):
            conv = ord if py2 else lambda x:x
            A = []; numb = zero; sign = 1; c = b'-'[0]
            for c in self.read():
                if c >= b'0'[0]: numb = 10 * numb + conv(c) - 48
                elif c == b'-'[0]: sign = -1
                elif c != b'\r'[0]: A.append(sign*numb); numb = zero; sign = 1
            if c >= b'0'[0]: A.append(sign*numb)
            return A
    
    class FastO(IOBase):
        def __init__(self, fd=1):
            stream = BytesIO()
            self.flush = lambda: os.write(1, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
            self.write = stream.write if py2 else lambda s: stream.write(s.encode())
    
    sys.stdin, sys.stdout = FastI(), FastO()
    global input
    input = sys.stdin.input


import sys

class ostream:
    def __lshift__(self,a):
        if a == endl:
            sys.stdout.write('\n')
            sys.stdout.flush()
        else:
            sys.stdout.write(str(a))
        return self
    def tie(self, val):pass
cout = ostream()
endl = object()

inp = []
def get():
    global inp
    if not inp:
        inp = sys.stdin.readline().split()[::-1]
    return inp.pop()

class istream:
    tiedto = cout
    def __rlshift__(a,b):
        if a.tiedto == cout:
            sys.stdout.flush()
        if type(b)==tuple or type(b)==list:
            return type(b)(type(c)(get()) for c in b)
        return type(b)(get())
    def tie(self, val):
        self.tiedto = val
cin = istream()

class Vector:
    def __lshift__(self, other):
        self.type = other
        return self
    def __rshift__(self, other):
        if type(other) == tuple:
            return [self.type(other[1])]*other[0]
        else:
            return [self.type()]*other
vector = Vector()



##### PYTHON++

#pragma GCC optimize ("O3")
#pragma GCC target ("avx,avx2")

sync_with_stdio(False);
cin.tie(0); cout.tie(0);

n = 0;
n <<= cin;
C = vector<<int>>(n);
C <<= cin;

i = n-1;
while (i>0 and C[i]==C[0]):
    i -= 1;

j = 0;
while (j<n-1 and C[j]==C[n-1]):
    j += 1;

cout << max(i, n-1-j) << endl;