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 java.io.*;
    import java.math.BigInteger;
    import java.util.*;
    import java.util.LinkedList;

    public class Main {
        static BigInteger[] dp = new BigInteger[10000];

        static BigInteger fib(int n) {
            n -= 1;
            if (n <= 1) return BigInteger.ONE;
            if (dp[n] != null) return dp[n];
            dp[0] = BigInteger.ONE;
            dp[1] = BigInteger.ONE;
            dp[n] = dp[n-1].add(dp[n-2]);
            return dp[n];
        }
        static long solve(int n) {
            if(n<=2) return n*2;
            long [] dp = new long[n];
            dp[0] = 2;
            dp[1] = 4;
            dp[2] = 7;
            int numberOfWhite = 1;
            for (int i = 3; i < n; i++) {
                dp[i] = (dp[i-1]-numberOfWhite)*2 + 1;
                numberOfWhite*=2;
            }
            return dp[n-1];
        }
        private static int convert(int first, int second) {
            int k = 1;
            int equation = second-first+k*26;
            while(equation<97) {
                k++;
                equation = second-first+k*26;
            }
            return equation;
        }
        private static boolean check(int n) {
            return n>=97 && n<=122;
        }
        public static void main(String[] args) throws IOException {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);

            int n = in.nextInt();
            int [] a = new  int [n];
            int max = 0;
            for (int i = 0; i < a.length; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < a.length; i++) {
                if(a[i]!=a[0]) max = Math.max(max,i);
            }
            for (int i = 0; i < a.length; i++) {
                if(a[i]!=a[n-1]) {
                    max = Math.max(max,n-1-i);
                }
            }
            out.println(max);

            out.flush();
        }
        private static String anotherPath(String s) {
            char [] c = s.toCharArray();
            char [] newS = new char[c.length];
            for (int i = 0; i < c.length; i++) {
                if(c[i]=='E') {
                    newS[i] = 'S';
                }
                else {
                    newS[i] = 'E';
                }
            }
            return new String(newS);
        }
        private static String newPath(String s, int l) {
            char [] c = s.toCharArray();
            StringBuilder sb = new StringBuilder();
            // check for SS...EE..
            // check for EE..SS..
            char first = c[0];
            char last = c[c.length - 1];
            if(first!=last) {
                // he comes from top
                if(last == 'S') {
                    for (int i = 0; i < l-1; i++) {
                        sb.append("S");
                    }
                    for (int i = 0; i < l-1; i++) {
                        sb.append("E");
                    }
                }
                else {
                    for (int i = 0; i < l-1; i++) {
                        sb.append("E");
                    }
                    for (int i = 0; i < l-1; i++) {
                        sb.append("S");
                    }
                }
            }
            else {
                // begins and ends with E
                if(first == 'E') {
                    sb.append("S");
                    for (int i = 0; i < l-1; i++) {
                        sb.append("E");
                    }
                    for (int i = 0; i < l-2; i++) {
                        sb.append("S");
                    }
                }
                else {
                    sb.append("E");
                    for (int i = 0; i < l-1; i++) {
                        sb.append("S");
                    }
                    for (int i = 0; i < l-2; i++) {
                        sb.append("E");
                    }
                }
            }


            return sb.toString();
        }
        private static boolean isSSEEorEESS(char [] c) {
            char first = c[0];
            int count = 1;
            for (int i = 1; i < c.length; i++) {
                if(c[i]==first) {
                    count++;
                }
                else {
                    break;
                }
            }
            return  (count<c.length/2);
        }
        private static void fillVisited(String  s, boolean [][] visited) {
            char [] c = s.toCharArray();
            int i=0,j=0;
            visited[i][j] = true;
            for (int k = 0; k < c.length; k++) {
                if(c[k]=='E') {
                    visited[i][++j] = true;
                }
                else {
                    visited[++i][j] = true;
                }
            }
        }

        private static boolean isTheSame(char [] c) {
            Arrays.sort(c);
            for (int i = 0; i < c.length - 1; i++) {
                if(c[i+1] - c[i]!=1) return false;
            }
            return true;
        }
        private static int solveToCheck(int n) {
            int max= Integer.MIN_VALUE;
            int number = 1;
            for (int i = 1; i <=n; i++) {
                if(product(i) > max) {
                    max = product(i);
                    number = i;
                }
            }
            return max;
        }
        private static int product(int n) {
            int p = 1;
            while (n>0) {
                p*=n%10;
                n/=10;
            }
            return p;
        }
        private static void reverseTheString(char [] s, int i, int j) {
            if(i == j) return;
            char temp = s[i];
            s[i] = s[j];
            s[j] = temp;
            i++;
            j--;
            reverseTheString(s,i,j);
        }
        public static String reverseString(String str){

            if(str.isEmpty()){
                return str;
            } else {
                System.out.println(str.substring(1) + str.charAt(0));
                return reverseString(str.substring(1))+str.charAt(0);
            }
        }

        private static void shuffleAnArray(int [] a) {
            for (int i = 0; i < a.length; i++) {
                int index = (int)Math.random()*a.length;
                int temp = a[i];
                a[i] = a[index];
                a[index] = temp;
            }
        }
        public static List<String> commonChars(String[] A) {
            int [][] freqs = new int[A.length][26];
            for(int i=0;i<freqs.length;i++) {
                freqs[i] = freq(A[i]);
            }
            List<String> result = new ArrayList<>();
            for(int i=0;i<26;i++) {
                boolean exit = false;
                int min = Integer.MAX_VALUE;
                for(int j=0;j<freqs.length;j++) {
                    if(freqs[j][i]==0) {
                        exit = true;
                        break;
                    }
                    else {
                        min = Math.min(min,freqs[j][i]);
                    }
                }
                if(!exit) {
                    for(int k=0;k<min;k++) {
                        char c = (char)(i + 'a');
                        result.add(Character.toString(c));
                    }
                }
            }
            return result;
        }
        static int [] freq (String a) {
            int [] frequency = new int[26];
            for(char c : a.toCharArray()) {
                frequency[c-'a']++;
            }
            return frequency;
        }

        static void printMap(LinkedHashMap<Integer,Integer> map) {
            for (Map.Entry<Integer,Integer> m : map.entrySet()) {
                System.out.println(m.getKey() + " " + m.getValue());
            }
        }

        static int upperBound(int [] arr, int target) {
            int lo = 0;
            int hi = arr.length - 1;
            while(lo<=hi) {
                int med = hi-(hi-lo)/2;
                if(target>=arr[med]) lo = med + 1;
                else hi = med - 1;
            }
            return hi;
        }
        static int currentDrawBack(int a,int b,int c, int d) {
            int max = Math.max(a,b);
            int min = Math.min(c,d);
            return min-max+1;
        }
        static int lowerBound1(Integer [] a,int target) {
            int lo = 0;
            int hi = a.length - 1;
            while(lo<=hi) {
                int med = hi-(hi-lo)/2;
                if(target<=a[med]) hi = med - 1;
                else lo = med + 1;
            }
            return lo;
        }
        static int lowerBound(int [] a,int target) {
            int lo = 0;
            int hi = a.length - 1;
            while (lo<=hi) {
                int med = hi-(hi-lo)/2;
                if(target<=a[med]) {
                    hi = med - 1;
                }
                else {
                    lo = med + 1;
                }
            }
            return lo;
        }

        private static void reverse(char [] c, int k, int index) {
            for(int i=index;i<(2*index+k)/2;i++) {
                System.out.println(i + " " + (k-index - 1));
                char temp = c[i];
                c[i] = c[k-i-1];
                c[k-i-1] = temp;
            }

        }
        static boolean isVowel(char c) {
            return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
        }
        private static String whoWin(int [] a) {
            TreeMap<Integer,Integer> map = new TreeMap<>(Comparator.reverseOrder());
            for(int n:a) {
                map.put(n,map.getOrDefault(n,0)+1);
            }
            for(Map.Entry<Integer,Integer> m:map.entrySet()) {
                if(m.getValue()%2==1) return "Conan";
            }
            return "Agasa";
        }


        private static int [] prefixSum(int [] a) {
            int [] prefix = new int[a.length+1];
            for(int i=1;i < prefix.length;i++) {
                prefix[i] = prefix[i-1] + a[i-1];
            }
            return prefix;
        }
        private static int [] charFrequency(String a) {
            int [] freq = new int[26];
            char [] cc = a.toCharArray();
            for(char c : cc) {
                freq[c-'a']++;
            }
            return freq;
        }
    }

    class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }
        public Long nextLong() {return  Long.valueOf(next());}

        static class OutputWriter extends PrintWriter {
            public OutputWriter(OutputStream outputStream) {
                super(outputStream);
            }

            public OutputWriter(Writer writer) {
                super(writer);
            }

            public OutputWriter(String filename) throws FileNotFoundException {
                super(filename);
            }

            public void close() {
                super.close();
            }
        }
    }
