// yukicoder: No.123 カードシャッフル // 2019.5.13 bal4u #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { int n = 0, c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } typedef struct { int id, prev, next; } T; T t[52]; int top, end; int res; void card(int n) { int i; for (i = 0; i < n; i++) t[i].id = i+1, t[i].prev = i-1, t[i].next = i+1; top = 0, end = n-1, res = 1; } void shuffle(int a) { int k, p, n; if (a == 1) return; k = top; while (--a) k = t[k].next; res = t[k].id, p = t[k].prev, n = t[k].next; if (k != end) t[p].next = n, t[n].prev = p; t[k].next = top, t[top].prev = k; top = k, end = p; } int main() { int N, M; N = in(); if (N == 1) { puts("1"); return 0; } card(N); M = in(); while (M--) shuffle(in()); printf("%d\n", res); return 0; }