import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      int[][] z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = new int[y][2];
      for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      }
      scanner.close();
      int sum = 0;
      int i,j;
      int maxz = 0;
      int minz = 100001;
         for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      }
      if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      }
   }
} import java.util.Scanner; Scanner java.util import java.util.InputMismatchException; InputMismatchException java.util class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      int[][] z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = new int[y][2];
      for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      }
      scanner.close();
      int sum = 0;
      int i,j;
      int maxz = 0;
      int minz = 100001;
         for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      }
      if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      }
   }
} Main public static void main(String args[]) {
      int x=0 ,y=0;
      int[][] z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = new int[y][2];
      for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      }
      scanner.close();
      int sum = 0;
      int i,j;
      int maxz = 0;
      int minz = 100001;
         for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      }
      if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      }
   } main {
      int x=0 ,y=0;
      int[][] z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = new int[y][2];
      for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      }
      scanner.close();
      int sum = 0;
      int i,j;
      int maxz = 0;
      int minz = 100001;
         for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      }
      if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      }
   } int x=0 x 0 y=0; y 0 int[][] z; z Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) x = scanner.nextInt() x scanner.nextInt() scanner.nextInt scanner y = scanner.nextInt() y scanner.nextInt() scanner.nextInt scanner z = new int[y][2] z new int[y][2] y 2 for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      } int i=0; int i=0; i 0 i<y i y i++ i++ i {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      } {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      } for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         } int j=0; int j=0; j 0 j<2 j 2 j++ j++ j {
            z[i][j] = scanner.nextInt();
         } {
            z[i][j] = scanner.nextInt();
         } z[i][j] = scanner.nextInt() z[i][j] z[i] z i j scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int sum = 0; sum 0 int i i j; j int maxz = 0; maxz 0 int minz = 100001; minz 100001 for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      } j=0; j=0 j 0 j<y j y j++ j++ j {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      } {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      } if (maxz < z[j][0]) {
               maxz = z[j][0];
            } maxz < z[j][0] maxz z[j][0] z[j] z j 0 {
               maxz = z[j][0];
            } maxz = z[j][0] maxz z[j][0] z[j] z j 0 if (minz > z[j][1]) {
               minz = z[j][1];
            } minz > z[j][1] minz z[j][1] z[j] z j 1 {
               minz = z[j][1];
            } minz = z[j][1] minz z[j][1] z[j] z j 1 if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      } minz-maxz > -1 minz-maxz minz maxz -1 1 {
         System.out.println(minz-maxz+1);
      } System.out.println(minz-maxz+1) System.out.println System.out System System.out minz-maxz+1 minz-maxz minz maxz 1 {
         System.out.println(0);
      } System.out.println(0) System.out.println System.out System System.out 0 String args[] args
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int x=0 ,y=0;
      int[][] z;
      Scanner scanner = new Scanner(System.in);
      x = scanner.nextInt();
      y = scanner.nextInt();
      z = new int[y][2];
      for (int i=0; i<y; i++) {
         for (int j=0; j<2; j++) {
            z[i][j] = scanner.nextInt();
         }
      }
      scanner.close();
      int sum = 0;
      int i,j;
      int maxz = 0;
      int minz = 100001;
         for (j=0; j<y; j++) {
            if (maxz < z[j][0]) {
               maxz = z[j][0];
            }
            if (minz > z[j][1]) {
               minz = z[j][1];
            }
      }
      if (minz-maxz > -1) {
         System.out.println(minz-maxz+1);
      } else {
         System.out.println(0);
      }
   }
}
