#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1e9;
int N, M;
vector<int> res;

vector<int> simu(const vector<vector<bool>> &A){
  vector<int> ret(N+1);
  for(int i = 0; i < N+1; ++i) ret[i] = i;
  for(size_t j = 0; j < A[0].size(); ++j){
    for(size_t i = 0; i < ret.size(); ++i){
      if(A[i][j]) swap(ret[i],ret[i+1]);
    }
  }
  return ret;
}

int dfs(vector<int> &A, vector<int> &H, vector<vector<bool>> &B, int idx){
  int ret = INF;
  if(idx == A.size()){
    vector<int> s = simu(B);
    if(s == res) return *max_element(H.begin(),H.end());
    else return INF;
  }
  int a = A[idx];
  for(int i = H[a]+1; i < M; ++i){
    if(B[a+1][i] or B[a-1][i] or B[a][i]) continue;
    B[a][i] = true;
    int h = H[a];
    H[a] = i;
    ret = min(ret,dfs(A,H,B,idx+1));
    H[a] = h;
    B[a][i] = false;
  }
  return ret;
}

int main(){
  cin >> N >> M;
  vector<int> A(M);
  vector<vector<bool>> B(N+1,vector<bool>(M,false));
  for(int i = 0; i < M; ++i){
    cin >> A[i];
    B[A[i]][i] = true;
  }
  res = simu(B);
  vector<vector<bool>> B_(N+1,vector<bool>(M,false));
  vector<int> H(N,-1);
  cout << dfs(A,H,B_,0)+1 << endl;
}

