R(n,r,p){//rñÌtriffle-shuffleÉæèÊupÌJ[hÍÇÌÊuÖßé©H
	int c,m;
	if(r){
		scanf("%d",&c);
		p=R(n,r-1,p);
		m=n-n/(c*2)*(c*2);//deckCÌ¼[
		if(p<n-m)//c¸Â¬º½ª
			return (1-p/c%2)*(n/2)+(p/c/2*c)+(p%c);
		else if(p<n-m/2)//deckAÌ¼[ª
			return n-(n-m/2-p);
		else//deckBÌ¼[ª
			return n/2-(n-p);
	}else{
		return p;
	}
}
main(){
	int n,r;
	for(;~scanf("%d%d",&n,&r);){
		printf("%d\n",R(n,r,n-1));
	}
}