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 java.io.BufferedOutputStream;
	import java.io.BufferedReader;
	import java.io.InputStreamReader;
	import java.io.PrintWriter;
	import java.util.*;

	
	public class e {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 
	
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
	
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
	
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
	
		double nextDouble() {
			return Double.parseDouble(next());
		}
	
		long nextLong() {
			return Long.parseLong(next());
		}
	
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	static ArrayList<String>list1=new ArrayList<String>();
	static void combine(String instr, StringBuffer outstr, int index,int k)
	{
		if(outstr.length()==k)
		{
			list1.add(outstr.toString());return;
		}
		if(outstr.toString().length()==0)
		outstr.append(instr.charAt(index));
	    for (int i = 0; i < instr.length(); i++)
	    {
	        outstr.append(instr.charAt(i));
	       
	        combine(instr, outstr, i + 1,k);
	        outstr.deleteCharAt(outstr.length() - 1);
	    }
	   index++;
	} 
	static ArrayList<ArrayList<Integer>>l=new ArrayList<>();
	static void comb(int n,int k,int ind,ArrayList<Integer>list)
	{
		if(k==0)
		{
			l.add(new ArrayList<>(list));
	
			return;
		}
		
		
		for(int i=ind;i<=n;i++)
		{
			list.add(i);
			comb(n,k-1,ind+1,list);
			
			list.remove(list.size()-1);
			
		}
		
		
		
		
		
	
	}
	
	static class Pair implements Comparable<Pair>{
	    int x;int y;
	    Pair(int x,int y){
	        this.x=x;
	        this.y=y;
	      //  this.i=i;
	    }
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			return (o.x*y-o.y*x);
			
		}
	}
	
		
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	  static HashMap<Long, Pair> sort(HashMap<Long, Pair> hm) 
	    { 
	        // Create a list from elements of HashMap 
	        List<Map.Entry<Long, Pair> > list = 
	               new LinkedList<Map.Entry<Long, Pair> >(hm.entrySet()); 
	  
	        // Sort the list 
	        Collections.sort(list, new Comparator<Map.Entry<Long, Pair> >() { 
	            public int compare(Map.Entry<Long, Pair> o1,  
	                               Map.Entry<Long, Pair> o2) 
	            { 
	                return (o1.getValue().y)-(o2.getValue().y); 
	            } 
	        }); 
	          
	        // put data from sorted list to hashmap  
	        HashMap<Long, Pair> temp = new LinkedHashMap<Long, Pair>(); 
	        for (Map.Entry<Long, Pair> aa : list) { 
	            temp.put(aa.getKey(), aa.getValue()); 
	        } 
	        return temp; 
	    } 
	  static long ncr(long n, int k) 
	    { long m=(long)1e9+7;
	        long C[] = new long[k + 1]; 
	         
	        // nC0 is 1 
	        C[0] = 1;   
	       
	        for (int i = 1; i <= n; i++) 
	        { 
	            // Compute next row of pascal  
	            // triangle using the previous row 
	            for (int j = Math.min(i, k); j > 0; j--) 
	                C[j] = (C[j]%m + C[j-1]%m)%m; 
	        } 
	        return C[k]%m; 
	    } 
	  static long high(long n) 
	  { 
	        
	      long p = (long)(Math.log(n) /  
	                    Math.log(2L)); 
	      return (long)Math.pow(2L, p);  
	  }
	  static int findd(int a){
	        if (parent[a]!=a){
	            parent[a] = findd(parent[a]);
	        }
	        return parent[a];
	    }
	 static int parent[];
	 static ArrayList<Integer>list=new ArrayList<Integer>();
	 static HashMap<Integer,Integer>map;
	 static boolean find(int n,int f)
	 {
		 if(map.containsKey(n))
		 {	
			 if(map.get(n)>=f)
			 {
				 map.put(n, map.get(n)-f);
				 if(map.get(n)==0)
					 map.remove(n);
				 return true;
			 }
			 else
			 {
				 f-=map.get(n);
				 map.remove(n);
				 if(find(n/2,2*f))
					 return true;
				 else
					 return false;
			 }
			
		 }
		 else if(n>1)
		 {
			if(find(n/2,2*f))
				return true;
			else
				return false;
		 }
		 else
			 return false;
	
	 }
		static int CeilIndex(int A[], int l, int r, int key) 
		{ 
			while (r - l > 1) { 
				int m = l + (r - l) / 2; 
				if (A[m] >= key) 
					r = m; 
				else
					l = m; 
			} 

			return r; 
		} 
static ArrayList<Character>li=new ArrayList<Character>();
		static int LongestIncreasingSubsequenceLength(int A[], int size) 
		{ 
			// Add boundary case, when array size is one 

			int[] tailTable = new int[size]; 
			int len; // always points empty slot 

			tailTable[0] = A[0]; 
			len = 1; 
			for (int i = 1; i < size; i++) { 
				if (A[i] < tailTable[0]) 
					// new smallest value 
					tailTable[0] = A[i]; 

				else if (A[i] > tailTable[len - 1]) 
					// A[i] wants to extend largest subsequence 
					tailTable[len++] = A[i]; 

				else
					// A[i] wants to be current end candidate of an existing 
					// subsequence. It will replace ceil value in tailTable 
					tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; 
			} 
	      for(int i=0;i<len;i++)
	        System.out.println(tailTable[i]);
	      

			return len; 
		} 
	 
		
		
		
		
		public static void main(String[] args) {
			// TODO Auto-generated method stub
	
		FastReader in=new FastReader();
		//ArrayList<String>list=new ArrayList<String>();
		
      HashMap<Integer,Integer>map=new HashMap<Integer,Integer>();
     
      int n=in.nextInt();
      Stack<Integer>st=new Stack<Integer>();
      int a[]=new int[n];
      for(int i=0;i<n;i++)
    	  a[i]=in.nextInt();
      int ans=0;
      int ct=1;
      for(int i=1;i<n;i++)
      {
    	  if(a[i]!=a[0])
    		  ans=Math.max(ans, ct);
    	  ct++;
      }
      ct=1;
      for(int i=n-2;i>=0;i--)
      {
    	  if(a[i]!=a[n-1])
    		  ans=Math.max(ans, ct);
    	  ct++;
      }
      out.println(ans);
      out.flush();
		}
		
	}	
		
		
		
	
