#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N, M;
  scanf("%lld %lld", &N, &M);

  vector<ll> alist;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    alist.emplace_back(v);
  }

  mll m;

  ll ans;

  ll mex = 0;
  for (ll i = 0; i < M; i++) {
    ll v = alist[i];
    m[v]++;

    if (v == mex) {
      mex = v + 1;
      for (;;) {
        if (m[mex] == 0) {
          break;
        }
        mex++;
      }
    }
  }

  ans = mex;

  ll left = 0;
  ll right = M - 1;

  for (;;) {
    if (right >= N - 1) {
      break;
    }

    ll lost_value = alist[left];
    ll new_value = alist[right + 1];

    // cout << "lost_value:" << (lost_value) << ",new_value:" << (new_value) << endl;

    m[lost_value]--;
    m[new_value]++;

    ll new_mex = mex;

    if (lost_value == new_value) {
      // NOP
    } else if (m[lost_value] == 0 && lost_value < mex) {
      new_mex = lost_value;
    } else if (new_value == mex) {
      new_mex = new_value + 1;
      for (;;) {
        if (m[new_mex] == 0) {
          break;
        }
        new_mex++;
      }
    }

    left++;
    right++;

    mex = new_mex;

    chmin(ans, new_mex);
  }

  cout << ans << endl;
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow 
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14 
/**#pragma GCC target ("avx2")  
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>  
#include <ext/pb_ds/assoc_container.hpp>
#define int long long 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ar[n+1];
    rep(i,0,n+1)
    cin>>ar[i];
    int mi=1e6;
    rep(i,1,n+1)
    mi=min(mi, abs(ar[i]-ar[i-1]));
    cout<<mi<<"\n";
    int b[mi][n+1];
    int sub=0;
    rep(i,0,n+1)
    {
        int base=ar[i]/mi;
        int lim=ar[i]%mi;
        rep(j,0,lim)
        b[j][i]=base+1;
        rep(j,lim,mi)
        b[j][i]=base;
    }
    print2d(b, mi-1, n);
}