#include <stdio.h> #include <stdlib.h> //#include <string.h> int main(void) { int L,M; int a,b; int *p; int i; int count=0; while((scanf("%d%d",&L,&M),L)) { p=(int *)malloc(sizeof(int)*(L+1)); //memset(p,0,L+1); for(i=0;i<L+1;i++) { p[i] = 0; } while(M) { scanf("%d%d",&a,&b); for(i=a;i<=b;i++) { p[i] = 1; } M--; } count = 0; for(i=0;i<L+1;i++) { if(p[i] == 0) { count++; } } free(p); printf("%d\n",count); } return 0; } /************************************************************** Problem: 2189 User: admin Language: C Result: Accepted Time:12 ms Memory:1144 kb ****************************************************************/