Toad Zitz has an array of integers, each integer is between 0 and m-1 inclusive. The integers are a_1, a_2, …, a_n.

In one operation Zitz can choose an integer k and k indices i_1, i_2, …, i_k such that 1 ≤ i_1 < i_2 < … < i_k ≤ n. He should then change a_{i_j} to ((a_{i_j}+1) mod m) for each chosen integer i_j. The integer m is fixed for all operations and indices.

Here x mod y denotes the remainder of the division of x by y.

Zitz wants to make his array non-decreasing with the minimum number of such operations. Find this minimum number of operations.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 300 000) — the number of integers in the array and the parameter m.

The next line contains n space-separated integers a_1, a_2, …, a_n (0 ≤ a_i < m) — the given array.

Output

Output one integer: the minimum number of described operations Zitz needs to make his array non-decreasing. If no operations required, print 0.

It is easy to see that with enough operations Zitz can always make his array non-decreasing.

Examples

Input


5 3
0 0 0 1 2


Output


0


Input


5 7
0 6 1 3 2


Output


1

Note

In the first example, the array is already non-decreasing, so the answer is 0.

In the second example, you can choose k=2, i_1 = 2, i_2 = 5, the array becomes [0,0,1,3,3]. It is non-decreasing, so the answer is 1.



    import java.io.*;
    import java.util.*;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.util.Collections;
    import java.io.InputStreamReader;
    import static java.lang.Math.*;
    import static java.lang.System.*;

    public class Main1 {


        static boolean Possible(int n , int m , int a[] , int moves){
            int tt[] = Arrays.copyOf(a , n) ;
            tt[n-1] = min(m-1 , tt[n-1]+moves) ;

            for (int i=n-2 ; i>=0 ; i--){
                if (tt[i] <= tt[i+1]){
                    tt[i] = min(tt[i+1] , tt[i]+moves) ;
                }
                else {
                    if (tt[i] + moves < m)return false ;

                   int  to_inc = (tt[i] + moves)%m ;
                   tt[i] = 0 ;
                    tt[i] = min(tt[i+1] , tt[i]+to_inc) ;
                }
                if (tt[i] > tt[i+1])return false ;
            }
            return true ;
        }




        public static void main(String[] args) throws IOException {

//           try {
            // Scanner in = new Scanner(System.in) ;
              FastScanner in = new FastScanner();
           PrintWriter out = new PrintWriter(System.out);



            int n = in.nextInt() ;
            int m = in.nextInt() ;
            int a[] = in.readArray(n) ;
            int l = 0 ;
            int r = m ;
            int ans = m ;

            while (l != r){
                int mid = (l+r)/2 ;
                if (Possible(n , m , a , mid)){
                    ans = mid ;
                    r = mid ;
                }
                else l = mid+1 ;

            }

            System.out.println(ans);






            out.flush();
            out.close();

//        }
//            catch (Exception e){
//                return;
//            }

        }

        static long gcd(long a, long b) {
            return (b == 0) ? a : gcd(b, a % b);
        }

        static int gcd(int a, int b) {
            return (b == 0) ? a : gcd(b, a % b);
        }

        static void sort(int ar[]) {
            int n = ar.length;
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++)
                a.add(ar[i]);
            Collections.sort(a);
            for (int i = 0; i < n; i++)
                ar[i] = a.get(i);
        }

        static void sort1(long ar[]) {
            int n = ar.length;
            ArrayList<Long> a = new ArrayList<>();
            for (int i = 0; i < n; i++)
                a.add(ar[i]);
            Collections.sort(a);
            for (int i = 0; i < n; i++)
                ar[i] = a.get(i);
        }

        static long ncr(long n, long r, long mod) {
            if (r == 0)
                return 1;
            long val = ncr(n - 1, r - 1, mod);
            val = (n * val) % mod;
            val = (val * modInverse(r, mod)) % mod;
            return val;
        }

        static long fast_pow(long base, long n, long M) {
            if (n == 0)
                return 1;
            if (n == 1)
                return base % M;
            long halfn = fast_pow(base, n / 2, M);
            if (n % 2 == 0)
                return (halfn * halfn) % M;
            else
                return (((halfn * halfn) % M) * base) % M;
        }

        static long modInverse(long n, long M) {
            return fast_pow(n, M - 2, M);
        }

    // ======================================================================================================



        static class FastOutput implements AutoCloseable, Closeable, Appendable {
            private static final int THRESHOLD = 32 << 10;
            private final Writer os;
            private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

            public FastOutput append(CharSequence csq) {
                cache.append(csq);
                return this;
            }

            public FastOutput append(CharSequence csq, int start, int end) {
                cache.append(csq, start, end);
                return this;
            }

            private void afterWrite() {
                if (cache.length() < THRESHOLD) {
                    return;
                }
                flush();
            }

            public FastOutput(Writer os) {
                this.os = os;
            }

            public FastOutput(OutputStream os) {
                this(new OutputStreamWriter(os));
            }

            public FastOutput append(char c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput append(long c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput append(String c) {
                cache.append(c);
                afterWrite();
                return this;
            }

            public FastOutput println() {
                return append(System.lineSeparator());
            }

            public FastOutput flush() {
                try {
                    //            boolean success = false;
                    //            if (stringBuilderValueField != null) {
                    //                try {
                    //                    char[] value = (char[]) stringBuilderValueField.get(cache);
                    //                    os.write(value, 0, cache.length());
                    //                    success = true;
                    //                } catch (Exception e) {
                    //                }
                    //            }
                    //            if (!success) {
                    os.append(cache);
                    //            }
                    os.flush();
                    cache.setLength(0);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
                return this;
            }

            public void close() {
                flush();
                try {
                    os.close();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }

            public String toString() {
                return cache.toString();
            }

        }


        static class FastScanner {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            StringTokenizer st = new StringTokenizer("");

            String next() {
                while (!st.hasMoreTokens())
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                return st.nextToken();
            }

            int nextInt() {
                return Integer.parseInt(next());
            }

            int[] readArray(int n) {
                int[] a = new int[n];
                for (int i = 0; i < n; i++) a[i] = nextInt();
                return a;
            }


            long nextLong() {
                return Long.parseLong(next());
            }
        }


    }







