#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[1010],f[110][110];
int main(void)
{
freopen("prison.in","r",stdin);
freopen("prison.out","w",stdout);
int i,j,k,p,q;
cin>>p>>q;
a[0]=0;
a[q+1]=p+1;
for (i=1;i<=q;i++)
cin>>a[i];
sort(a+1,a+1+q);
for (i=1;i<=q;i++)
f[i][1]=a[i+1]-a[i-1]-2;
for (i=1;i<q;i++)
f[i][2]=min(f[i][1],f[i+1][1])+a[i+2]-a[i-1]-2;
for (j=3;j<=q;j++)
for (i=1;i+j-1<=q;i++)
{
f[i][j]=min(f[i][j-1],f[i+1][j-1]);
for (k=i+1;k<=i+j-1-1;k++)
f[i][j]=min(f[i][j],f[i][k-1-i+1]+f[k+1][i+j-1-(k+1)+1]);
f[i][j]+=a[i+j]-a[i-1]-2;
}
cout<<f[1][q]<<endl;
return(0);
}