#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
using namespace std;

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll n,m;
  cin>>n>>m;
  vll vec(m);
  FOR(i,0,m){
    cin>>vec[i];
  }
  bool D=false;
  if(vec[0]==1){
    D=true;
  }
  if(m>1){
  FOR(i,1,m){
    if((vec[i]-vec[i-1])==1){
      D=true;
    }
  }
  }
  if((n-vec[m-1])==1){
    D=true;
  }
  if(D){
    co(0);
  }
  else{
  vll v2(18);
    //1 iranai
  ll a2=1;
  FOR(i,0,18){
    v2[i]=a2;
    a2*=2;
  }
  //nisinsuu ni surun ha pass
  //keisanryou ha daizyoubu yoteidoutinara
  ll bns=0,ans=0;
    ll b=0;
  FOR(j,0,18){
    if((vec[0]-1)>=v2[j]){
      bns+=vec[0]/v2[j]+vec[0]%v2[j];
    }
    else break;
  }
  ans+=bns;
  ll a=0;
  if(m>1){
  FOR(i,1,m){
    a=vec[i]-vec[i-1]-1;
    FOR(j,0,17){
      if(a>=v2[j]){
        bns+=a/v2[j]+a%v2[j];
      }
      else break;
    }
    ans+=bns;
  }
  }
  a=n-vec[m-1]-1;
  FOR(j,0,17){
      if(a>=v2[j]){
        FOR(k,0,a%v2[j]){
    //if( (a/v2[j]+1)>a%v2[j];)
   //   (a/v2[j]+1) C a%v2[j];
    //else ...
        bns+=(a/v2[j]+1)a%v2[j];
      }
      else break;
    ans+=bns;
  }
  co(ans);
  }
}
  