#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
  
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
  
using namespace std;
  
typedef long long ll;
typedef pair<int, int> P;
 
const int INF = 1<<29;
 
int N, M;
vector<int> change(int* a){
    vector<int> v(N);
    rep(i, N) v[i] = i+1;
    rep(i, M) swap(v[a[i]], v[a[i]-1]);
    return v;
}
 
int a[100];
 
int check(vector<int> &res, vector<int> &v){
    rep(i, N) if(res[i] != v[i]) return 10000;
 
    int h[10] = {};
    rep(i, M){
        int x = h[a[i]];
        rep(j, 10) h[j] = max(h[j], x);
        for(int j = -1; j <= 1; j++) h[a[i]+j] = x+1;
    }
    return *(max_element(h, h+10));
}
 
int main(){
 
    cin >> N >> M;
    rep(i, M) cin >> a[M-i-1];
    vector<int> res = change(a);
 
    int ans = 10000;
    sort(a, a+M);
    do{
        vector<int> v = change(a);
        ans = min(ans, check(res, v));
    }while(next_permutation(a, a+M));
    cout << ans << endl;
 
    return 0;
}