let read_list () =
 String.split_on_char ' ' (read_line ());;

let read_list_int () =
 List.map int_of_string (read_list ());;

let rec read_input_list t list = match t with
   0 -> list
 | _ -> read_input_list (t - 1) (List.cons (read_list_int ()) list);;



let rec solve input k n = match input with
   [] -> k
 | [p; c] :: input ->
           if (n - k + 1 <= c) then
            solve input (k - p + 1) n
           else if (n - k + 1 <= (c + p - 1)) then
            solve input (k + c) n
           else
            solve input k n;;

let rec c_solve () =
 let [n; r] = read_list_int () in
  if (n == 0) then ()
  else
   let input = read_input_list r [] in
    (print_int (solve input n n); print_newline; c_solve ());;

let main () =
 let arg = int_of_string Sys.argv.(1) in
 c_solve ();
 exit 0;;

main ();;

