import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int l=scanner.nextInt(); if(l==0){ continue; } int m=scanner.nextInt(); boolean[] tree=new boolean[10010]; while(m--!=0){ int begin=scanner.nextInt(); int end=scanner.nextInt(); for (int i = begin; i <= end; i++) { tree[i]=true; } } int ans =0; for (int i = 0; i <= l; i++) { if(tree[i]==false){ ++ans; } } System.out.println(ans); } } } /************************************************************** Problem: 2189 User: admin Language: Java Result: Accepted Time:742 ms Memory:42440 kb ****************************************************************/