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. 
import javax.print.DocFlavor;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.io.*;
import java.math.BigInteger;
import java.nio.Buffer;
import java.sql.BatchUpdateException;
import java.util.*;
import java.util.stream.Stream;
import java.util.Vector;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import static java.lang.Math.*;
import java.util.*;
import java.nio.file.StandardOpenOption;
public class icpc
{
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        int n = in.nextInt();
        int[] A = new int[n];
        for(int i=0;i<n;i++)
            A[i] = in.nextInt();
        int len1 = Integer.MIN_VALUE;
        for(int j=n-1;j>1;j--)
        {
            if(A[0] != A[j])
            {
                len1 = j;
                break;
            }
        }
        int len2 = Integer.MIN_VALUE;
        for(int i=0;i<n-1;i++)
        {
            if(A[i] != A[n-1])
            {
                len2 = n - 1 - i;
                break;
            }
        }
        System.out.println(Math.max(len1,len2));
    }
}
class Solver
{
    public void solve(long[] A,Game[] B)
    {
    }
}
class Point implements Comparable<Point>
{
    int x;
    int y;
    Point(int a ,int b)
    {
        this.x = a;
        this.y = b;
    }
    public int compareTo(Point ob)
    {
        if(ob.x < this.x)
            return 1;
        else if(ob.x > this.x)
            return -1;
        else
            return 0;
    }
}
class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];


        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}
class Node
{
    int[] A;
    int moves;
    Node(int[] B,int c)
    {
        this.A = new int[B.length];
        A = B.clone();
        this.moves = c;
    }
    @Override
    public boolean equals(Object ob)
    {
        if(ob == null)
            return false;
        if(!(ob instanceof Node))
            return false;
        if(ob == this)
            return true;
        Node obj = (Node)ob;
        boolean flag = true;
        for(int i=0;i<obj.A.length;i++)
        {
            if(this.A[i] != obj.A[i])
                flag = false;
        }
        return (flag & (obj.moves == this.moves));
    }
    @Override
    public int hashCode()
    {
        return (int)this.A.length;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}
class Game
{
    int last;
    int diff;
    boolean flag;
    Game(int a,int b,boolean z)
    {
        this.last = a;
        this.diff = b;
        this.flag = z;
    }
}
class Play
{
    int x;
    int y;
    Play(int a,int b)
    {
        this.x = a;
        this.y = b;
    }
}
class SegmentTree1
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }
    public int[] createSegmentTree(int[] input)
    {
        int np2 = nextPowerOfTwo(input.length);
        int[] segmentTree = new int[np2 * 2 - 1];

        for(int i=0;i<segmentTree.length;i++)
            segmentTree[i] = Integer.MAX_VALUE;

        constructSegmentTree(segmentTree,input,0,input.length-1,0);
        return segmentTree;

    }
    private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
    {
        if(low == high)
        {
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high)/ 2;
        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
        segmentTree[pos] = Math.min(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQuery(int[] segmentTree,int qlow,int qhigh,int len)
    {
        return rangeMinimumQuery(segmentTree,0,len - 1,qlow,qhigh,0);
    }
    private int rangeMinimumQuery(int[] segmentTree,int low,int high,int qlow,int qhigh,int pos)
    {
        if(qlow <= low && qhigh >= high)
        {
            return segmentTree[pos];
        }
        else if(qlow > high || qhigh < low)
        {
            return Integer.MAX_VALUE;
        }
        int mid = (low + high)/2;
        return Math.min(rangeMinimumQuery(segmentTree,low,mid,qlow,qhigh,2*pos+1),rangeMinimumQuery(segmentTree,mid+1,high,qlow,qhigh,2*pos+2));
    }
    public void updateSegmentTreeRangeLazy(int[] input,int[] segmentTree,int[] lazy,int startRange,int endRange,int delta)
    {
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,0,input.length-1,0);
    }
    private void updateSegmentTreeRangeLazy(int[] input,int[] segmentTree,int[] lazy,int startRange,int endRange,int delta,int low,int high,int pos)
    {
        if(low > high)
        {
            return;
        }
        if(lazy[pos] != 0)
        {
            segmentTree[pos] += lazy[pos];
            if(low != high)
            {
                lazy[2*pos+1] += lazy[pos];
                lazy[2*pos + 2] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if(startRange > high || endRange < low)
            return;
        if(startRange <= low && endRange >= high)
        {
            segmentTree[pos] += delta;
            if(low != high)
            {
                lazy[2*pos + 1] += delta;
                lazy[2*pos + 2] += delta;
            }
            return;
        }
        int mid = (low + high)/2;
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,low,mid,2*pos + 1);
        updateSegmentTreeRangeLazy(input,segmentTree,lazy,startRange,endRange,delta,mid + 1,high,2 * pos + 2);
        segmentTree[pos] += Math.min(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQueryLazy(int[] segmentTree,int[] lazy,int qlow,int qhigh,int len)
    {
        return rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,0,len - 1,0);
    }
    private int rangeMinimumQueryLazy(int[] segmentTree,int[] lazy,int qlow,int qhigh,int low,int high,int pos)
    {
        if(low > high)
            return Integer.MAX_VALUE;
        if(lazy[pos] != 0)
        {
            segmentTree[pos] += lazy[pos];
            if(low != high)
            {
                lazy[2*pos + 1] += lazy[pos];
                lazy[2*pos + 2] += lazy[pos];
            }
            lazy[pos] = 0;
        }
        if(qlow > high || qhigh < low)
            return Integer.MAX_VALUE;
        if(qlow <= low && qhigh >= low)
            return segmentTree[pos];
        int mid = (low + high)/2;
        return Math.min(rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,low,mid,2*pos + 1),rangeMinimumQueryLazy(segmentTree,lazy,qlow,qhigh,mid + 1,high,2*pos + 2));
    }
}
class FenwickTree
{
    public void update(int[] fenwickTree,int delta,int index)
    {
        index += 1;
        while(index < fenwickTree.length)
        {
            fenwickTree[index] += delta;
            index = index + (index & (-index));
        }
    }
    public int prefixSum(int[] fenwickTree,int index)
    {
        int sum = 0;
        index += 1;
        while(index > 0)
        {
            sum += fenwickTree[index];
            index -= (index & (-index));
        }
        return sum;
    }
}
