import java.util.*; import static java.lang.Math.*; /* * solve the attack now and attack later case */ public class Cosmo { public static void main(String[] args){ Scanner in = new Scanner(System.in); while(true) { long ans = solveScanner(in); if (ans == Long.MIN_VALUE) break; System.out.println(ans); } } static long solveScanner(Scanner in) { long W = in.nextLong(); if (W == 0) return Long.MIN_VALUE; long P = in.nextLong(); int T = in.nextInt(); long[] attack = new long[T]; for (int i = 0; i < T-1; i++) { attack[i] = in.nextLong(); } try { return solve(W, P, T, attack); } catch (ArrayIndexOutOfBoundsException e) { return -2; } } static long solve(long W, long P, int t, long[] a) { attack = a; T = t; return solve(0, W, P, 0); } static long[] attack; static int T; static long MAX = 1000000000000000L; static long solve(int t, long w, long p, long a) { if (w > MAX || p > MAX || a > MAX) throw new ArrayIndexOutOfBoundsException(); if (a < 0) return -1; if (t == T) return a; long ans = -1; boolean atend = t+2 >= T; if (atend) { long na = min(p, w); long np = w-na; ans = solve(t+1, w, p+np, a + na - attack[t]); } else if (attack[t] == 0 && attack[t+1] == 0) { if (a > 0) return -1; long nw = p; nw = min(nw, w); long np = w - nw; ans = solve(t+1, w + nw, p + np, a); } else if(attack[t] != 0 && attack[t+1] == 0) { if (attack[t] - a > min(w, p)) return -1; long na = attack[t] - a; long nw = min(w, p) - na; long np = w - na - nw; ans = solve(t+1, w + nw, p + np, a + na - attack[t]); } else if(attack[t+1] != 0) { if (a > attack[t]) return -1; long fa = attack[t] - a; long wl = w - fa; long pl = p - fa; if (wl < 0 || pl < 0) return -1; // Try building no army this turn, but enough workers/production to // build them all next turn long nw = max(0, attack[t+1] - w); long np = max(0, attack[t+1] - p); if (nw + np <= wl && nw <= pl) { nw += min(wl - nw - np, pl - nw); np = wl - nw; ans = solve(t+1, w + nw, p + np, a + fa - attack[t]); } else { long fw = max(0, p - w); long fp = max(0, w - p); fw = min(fw, min(wl, pl)); fp = min(fp, wl); long next = min(w + fw, p + fp); long wpl = min(wl - fw - fp, pl - fw); long need = max(0, attack[t+1] - next); if (need > wpl) return -1; nw = np = wpl - need; long na = need - nw; nw += fw; np += fp; ans = solve(t+1, w + nw, p + np, a + na + fa - attack[t]); } } else { throw new RuntimeException(); } return ans; } }