#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require sqrt ceil floor
#include <climits>	// require INT_MAX etc
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <stdint.h>	// require uint64_t
#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.riffle_shuffle", "r", stdin );
	int n, r;

	while (cin >> n >> r && n && r ){
		vector <int> c (r, 0 );

		for (int i = 0; i < r; ++i){
			cin >> c[i];
		} // end for

		deque<int> A, B, C;
		for (int i = 0; i < n; ++i ){
			C.push_back (i);
		} // end for
		int size = C.size();

		for (int i = 0; i < r; ++i ){
			for (int j = 0; j < size/2; ++j ){
				B.push_back (C.front() ); C.pop_front();
			} // end for
			while (!C.empty() ){
				A.push_back (C.front() ); C.pop_front();
			} // while
			while (!A.empty() || !B.empty() ){
				for (int j = 0; j < c[i] && !A.empty(); ++j ){
					C.push_back (A.front() ); A.pop_front();
				} // end for
				for (int j = 0; j < c[i] && !B.empty(); ++j ){
					C.push_back (B.front() ); B.pop_front();
				} // end for
			} // end while
		} // end for
		cout << C.back() << endl;	
	} // end loop
		
	return 0;
}