File Edit Options Buffers Tools C Help
#include<stdio.h>
int main(void){
  int i, n, r, p, c;
  scanf("%d%d", &n, &r);
  int yama[n];
  for(i=0;i<n;i++){
    yama[i]=n-i;
  }
  while(1){
    scanf("%d%d", &p, &c);
    if(p==0 && c==0){
      break;
    }
    int down[p-1], cut[c];
    for(i=0;i<p-1;i++){
      down[i]=yama[i];
    }
    for(i=0;p-1+i<p-1+c;i++){
      cut[i]=yama[p-1+i];
    }
    for(i=0;i<p+c-1;i++){
      yama[i]=cut[i];
      yama[p-1+i]=down[i];
    }
  }

  printf("%d\n%d", yama[0], yama[0]);
  return 0;
}