Problem: Problem Statement

Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and always tries to save as much paper as possible. She decided to play a ghost leg with other participants to decide the team for the Aizu training camp.

How to make Amidakuji for this training camp is as follows. First, write N vertical bars in parallel on the paper. Then, write the M horizontal bars in order from the top so that they are perpendicular to the vertical bars and the heights of the horizontal bars are all different. For example, the Amida of Sample Input 1 is as shown in Fig. 1.

Here, Mr. Takatsuki, a little dissatisfied expression. It's a waste of paper to write a ghost leg so vertically. You should be able to compress the height more. So, I want her to solve the problem of height compression of Amidakuji shown below.

First, the height of the Amidakuji is the value obtained by counting the horizontal bars that exist at the same height together as the height 1 and counting this to the bottom horizontal bar. Here, it is assumed that each horizontal bar can be freely moved up and down in order to perform height compression. However, it is not permissible to remove or add horizontal bars. The Amidakuji after height compression must meet the following conditions.

* The end points of the horizontal bar do not touch the end points of other horizontal bars.
* The result of tracing the Amidakuji after compression and the result of tracing the Amidakuji before compression match.



FIG. 2 is a compressed version of FIG. The "horizontal bar connecting vertical bars 1 and 2" moves to the top and becomes the same height as the "horizontal bar connecting vertical bars 4 and 5", and these two are height 1. After that, the "horizontal bar connecting the vertical bars 3 and 4" and the "horizontal bar connecting the vertical bars 2 and 3" have different heights, and the total height is 3.

<image>

Compress the height of the given Amidakuji and output the compressed height.

Constraints

* 2 <= N <= 8
* 1 <= M <= 8
* 1 <= ai <= N --1

Input

Each data set is input in the following format.


N M
a1
a2
...
aM


All inputs are integers. N indicates the number of vertical bars and M indicates the number of horizontal bars. Then, the information of the horizontal bar is input over M lines. ai indicates that the i-th horizontal bar connects the vertical bar ai and the vertical bar to the right of it. The i-th horizontal bar exists above the i + 1-th horizontal bar.

Output

Outputs the height of the compressed Amidakuji in one line.

Examples

Input

5 4
4
3
1
2


Output

3


Input

4 3
1
2
3


Output

3

Solution (in CPP):

Solution:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#include<cstdio>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 8
#define inf (1<<29)

using namespace std;

int N,M,cnt;
int ans[MAX];
int input[MAX];
bool amida[MAX][MAX];

int solve(int *array)
{
  rep(i,N)array[i] = i;
  int mex,men;
  mex = -inf;
  men = inf;
  rep(h,8)
    {
      rep(w,N)
	{      
	  if(amida[h][w])
	    {
	      men = min(men,h);
	      mex = max(mex,h);
	      swap(array[w],array[w+1]);
	    }
	}
    }
  return mex - men + 1;
}

bool check(int *array)
{
  rep(i,N)if(array[i] != ans[i])return false;
  return true;
}


void dfs(int cur)
{
  if(cur >= M)
    {
      int array[N];
      int cost = solve(array);
      if(check(array))cnt = min(cnt,cost);
      return;
    }

  rep(h,8)
    {
      int w = input[cur];
      if(amida[h][w])continue;
      if(!amida[h][w-1] && !amida[h][w+1])
	{
	  amida[h][w] = true;
	  dfs(cur+1);
	  amida[h][w] = false;
	}
    }

}

int main()
{
  scanf("%d %d",&N,&M);

  rep(i,MAX)rep(j,MAX)amida[i][j] = false;
  rep(i,M)
    {
      scanf("%d",&input[i]);
      input[i]--;
      amida[i][input[i]] = true;
    } 
  cnt = solve(ans);
  assert(cnt == M);

  rep(h,8)rep(w,N)amida[h][w] = false;

  dfs(0);

  cout << cnt << endl;

  return 0;
}