#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


int main(){
  int n,r;
  while(cin>>n>>r){
    deque<int> Q;
    rep(i,n)Q.pb(i);

    rep(i,r){
      int c;
      cin>>c;

      deque<int> A,B,C;

      int qs=(Q.size())/2;
      rep(j,qs){
	if(Q.empty())break;
	int t=Q.front();Q.pop_front();
	B.pb(t);
      }

      while(!Q.empty()){
	int t=Q.front();Q.pop_front();
	A.pb(t);
      }


      while(!A.empty() || !B.empty()){
	
	for(int j=0;j<c && !A.empty();j++){
	  int t=A.front();A.pop_front();
	  C.pb(t);
	}

	for(int j=0;j<c && !B.empty();j++){
	  int t=B.front();B.pop_front();
	  C.pb(t);
	}
      }
      Q=C;
    }
    int ans;
    while(!Q.empty()){
      ans=Q.front();
      Q.pop_front();
    }
    cout<<ans<<endl;
  }
}