#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Data {
  int x,y;
  bool operator < ( const Data &data ) const {
    return y < data.y;
  }
};

int n,m,a[100],b[100],correct[100],buf[100],mini;
vector<Data> kuji;

bool check1(){
  rep(i,m) rep(j,m) if( i != j ) {
    if( kuji[i].x == kuji[j].x && kuji[i].y == kuji[j].y ) return false;
    if( abs(kuji[i].x-kuji[j].x) == 1 && kuji[i].y == kuji[j].y ) return false;
  }
  return true;
}

void dfs(int cur,int hight){
  if( hight >= mini ) return;


  if( cur >= m ) {
    if( !check1() ) return;
    vector<Data> vec;
    rep(i,m) vec.push_back(kuji[i]);
    sort(vec.begin(),vec.end());
    rep(i,n) buf[i] = i;
    rep(i,m) swap(buf[vec[i].x],buf[vec[i].x+1]);
    bool success = true;
    rep(i,n) if( buf[i] != correct[i] ) { success = false; break; }
    if( success ) mini = hight;
    return;
  }
  rep(y,m){
    Data temp = kuji[cur];
    kuji[cur].y = y;
    dfs(cur+1,max(hight,y+1));
    kuji[cur] = temp;
  }
}

int main(){
  cin >> n >> m;
  int perm[n];
  int cnt[n];
  rep(i,n) cnt[i] = 0;
  rep(i,n) correct[i] = perm[i] = i;
  rep(i,m) { cin >> a[i]; --a[i]; swap(correct[a[i]],correct[a[i]+1]); ++cnt[a[i]]; }
  mini = m;
  rep(i,n) {
    int y = 0;
    rep(j,cnt[i]) kuji.push_back((Data){i,y++});
  }
  dfs(0,0);
  cout << mini << endl;
  return 0;
}