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.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;



public class Main {
    private static int n,m;
    private static int [] A;

    private static boolean can(int k) {
        int e = m-1;
        for (int i = n-1;i >= 0;i--) {
            if (A[i] <= e) {
                int d = Math.min(k,e - A[i]);
                e = A[i] + d;
            }
            else {
                int num = m-A[i];
                if (num > k) return false;
                num += e;
                int d = Math.min(num,k);
                e = (A[i] + d)%m;
            }
        }
        return true;
    }

    public static void main(String[] args) throws Exception {
        IO io ;
        try {
            io = new IO("in.in", null);
        } catch (IOException e) {
            io = new IO(null, null);
        }
        n = io.getNextInt();
        m = io.getNextInt();
        A = new int[n];
        for (int i = 0;i < n;i++)
            A[i] = io.getNextInt();

        int s = 0,e = m-1;
        while (s < e){
            int mid = (s + e) >> 1;
            if(can(mid)) e = mid;
            else s = mid+1;
        }
        io.println(s);
        io.close();
    }
    private static final int onebillion7 = 1000000007;
}


class pair implements Comparable<pair>{
    int k,s;
    public pair(int a,int b) {
        k = a;
        s = b;
    }

    @Override
    public int compareTo(pair o) {
        if (k == o.k) return (s - o.s);
        return (k - o.k);
    }
}

class IO{
    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter writer;
    private String inputFile,outputFile;

    public boolean hasMore() throws IOException{
        if(st != null && st.hasMoreTokens()) return true;
        if(br != null && br.ready()) return true;
        return false;
    }

    public String getNext() throws FileNotFoundException, IOException{
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public String getNextLine() throws FileNotFoundException, IOException{
        return br.readLine().trim();
    }

    public int getNextInt() throws FileNotFoundException, IOException{
        return Integer.parseInt(getNext());
    }
    public long getNextLong() throws FileNotFoundException, IOException{
        return Long.parseLong(getNext());
    }

    public void print(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f" ,x);
    }
    public void println(double x,int num_digits) throws  IOException{
        writer.printf("%." + num_digits + "f\n" ,x);
    }
    public void print(Object o) throws  IOException{
        writer.print(o.toString());
    }

    public void println(Object o) throws  IOException{
        writer.println(o.toString());
    }
    public IO(String x,String y) throws FileNotFoundException, IOException{
        inputFile = x;
        outputFile = y;
        if(x != null) br = new BufferedReader(new FileReader(inputFile));
        else br = new BufferedReader(new InputStreamReader(System.in));
        if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        else writer = new PrintWriter(new OutputStreamWriter(System.out));
    }

    protected void close() throws IOException{
        br.close();
        writer.close();
    }
    public void outputArr(Object [] A) throws IOException{
        int L = A.length;
        for (int i = 0;i < L;i++) {
            if(i > 0) writer.print(" ");
            writer.print(A[i]);
        }
        writer.print("\n");
    }
}



//class PollardRho {
//    private final static BigInteger ZERO = new BigInteger("0");
//    private final static BigInteger ONE  = new BigInteger("1");
//    private final static BigInteger TWO  = new BigInteger("2");
//    private final static SecureRandom random = new SecureRandom();
//    private static ArrayList<Long> primes = new ArrayList<>();
//
//    private static BigInteger rho(BigInteger N) {
//        BigInteger divisor;
//        BigInteger c  = new BigInteger(N.bitLength(), random);
//        BigInteger x  = new BigInteger(N.bitLength(), random);
//        BigInteger xx = x;
//
//        // check divisibility by 2
//        if (N.base(TWO).compareTo(ZERO) == 0) return TWO;
//
//        do {
//            x  =  x.multiply(x).base(N).add(c).base(N);
//            xx = xx.multiply(xx).base(N).add(c).base(N);
//            xx = xx.multiply(xx).base(N).add(c).base(N);
//            divisor = x.subtract(xx).gcd(N);
//        } while((divisor.compareTo(ONE)) == 0);
//
//        return divisor;
//    }
//
//    private static void factor(BigInteger N) {
//        if (N.compareTo(ONE) == 0) return;
//        if (N.isProbablePrime(20)) {
//            primes.add(N.longValue());
//            return;
//        }
//        BigInteger divisor = rho(N);
//        factor(divisor);
//        factor(N.divide(divisor));
//    }
//
//
//    public static ArrayList<Long> factor(Long n) {
//        primes.clear();
//        factor(BigInteger.valueOf(n));
//        return primes;
//    }
//}

class complex{
    BigDecimal real,imag;
    private static DecimalFormat df = new DecimalFormat("#.###");
    public complex(double x,double y){
        real = new BigDecimal(x);
        imag = new BigDecimal(y);
    }
    public complex(BigDecimal x,BigDecimal y) {
        real = new BigDecimal(x.toString());
        imag = new BigDecimal(y.toString());
    }
    public complex(double t) {
        real = new BigDecimal(Math.cos(t));
        imag = new BigDecimal(Math.sin(t));
    }
    public complex add(complex o){
        return new complex(real.add(o.real),imag.add(o.imag));
    }
    public complex sub(complex o) {
        return new complex(real.subtract(o.real),imag.subtract(o.imag));
    }
    public complex mult(double c) {
        BigDecimal bc = new BigDecimal(c);
        return new complex(real.multiply(bc),imag.multiply(bc));
    }
    public complex mult(complex o) {
        BigDecimal a = real.multiply(o.real).subtract(imag.multiply(o.imag));
        BigDecimal b = real.multiply(o.imag).add(imag.multiply(o.real));
        return new complex(a,b);
    }
    public complex divide(complex o) {
        return this.mult(new complex(o.real,o.imag.negate())).divide(o.norm2());
    }
    public complex divide(double c) {
        BigDecimal bc = new BigDecimal(c);
        return new complex(real.divide(bc),imag.divide(bc));
    }
    public complex divide(BigDecimal bc) {
        return new complex(real.divide(bc),imag.divide(bc));
    }

    public BigDecimal norm2(){
        return real.multiply(real).add(imag.multiply(imag));
    }
    public double norm(){
        return Math.sqrt(norm2().doubleValue());
    }
    @Override
    public String toString(){
        return "(" + df.format(real) + ", " + df.format(imag) + ")";
    }
}

class FFT{
    public static long [] mult(long [] A,long [] B) {
        int n = A.length;
        while (n != (n & -n)) n++;
        n <<= 1;
        complex [] pA = new complex[n];
        complex [] pB = new complex[n];
        complex [] pC = new complex[n];
        for (int i = 0;i < n;i++) {
            if (i < A.length){
                pA[i] = new complex(A[i],0);
                pB[i] = new complex(B[i],0);
            }
            else {
                pA[i] = new complex(0,0);
                pB[i] = new complex(0,0);
            }
        }

        pA = fft(pA,false);
        pB = fft(pB,false);
        for (int i = 0;i < pC.length;i++)
            pC[i] = pA[i].mult(pB[i]);
        pC = fft(pC,true);
        long [] C = new long[n];
        for (int i = 0;i < n;i++) {
            long mod = 1000*1000*1000;
            BigDecimal bc = pC[i].real.remainder(new BigDecimal(mod));
            C[i] %= Math.round(bc.doubleValue());
        }
        return C;
    }
    private static complex[] fft(complex [] f,boolean inv) {
        if (f.length == 1) return f;
        int n = f.length;
        complex wn = new complex((inv ? -1 : 1)*2*Math.PI/n),w = new complex(1,0);
        complex [] E = new complex[n/2],O = new complex[n/2];
        for (int i = 0;i < n;i++){
            if (i%2 == 0) E[i >> 1] = f[i];
            else O[i >> 1] = f[i];
        }
        E = fft(E,inv);
        O = fft(O,inv);
        for (int k = 0;k < n/2;k++){
            f[k] = E[k].add(w.mult(O[k]));
            f[k+n/2] = E[k].sub(w.mult(O[k]));
            w = w.mult(wn);
        }
        return f;
    }
}