import java.util.Scanner;

class Main{
	public static void main (String[] args) {
		Scanner stdIn = new Scanner(System.in);
	    int n = stdIn.nextInt();
	    int m = stdIn.nextInt();
	    int[] l = new int[m];
	    int[] r = new int[m];
	    for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    }
	    int max = l[0];
	    int min = r[0];
	    for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    }
	    int k = min - max + 1;
	    if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k);
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main (String[] args) {
		Scanner stdIn = new Scanner(System.in);
	    int n = stdIn.nextInt();
	    int m = stdIn.nextInt();
	    int[] l = new int[m];
	    int[] r = new int[m];
	    for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    }
	    int max = l[0];
	    int min = r[0];
	    for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    }
	    int k = min - max + 1;
	    if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k);
	}
} Main public static void main (String[] args) {
		Scanner stdIn = new Scanner(System.in);
	    int n = stdIn.nextInt();
	    int m = stdIn.nextInt();
	    int[] l = new int[m];
	    int[] r = new int[m];
	    for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    }
	    int max = l[0];
	    int min = r[0];
	    for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    }
	    int k = min - max + 1;
	    if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k);
	} main {
		Scanner stdIn = new Scanner(System.in);
	    int n = stdIn.nextInt();
	    int m = stdIn.nextInt();
	    int[] l = new int[m];
	    int[] r = new int[m];
	    for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    }
	    int max = l[0];
	    int min = r[0];
	    for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    }
	    int k = min - max + 1;
	    if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int m = stdIn.nextInt(); m stdIn.nextInt() stdIn.nextInt stdIn int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    } {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    } l[i] = stdIn.nextInt() l[i] l i stdIn.nextInt() stdIn.nextInt stdIn r[i] = stdIn.nextInt() r[i] r i stdIn.nextInt() stdIn.nextInt stdIn int max = l[0]; max l[0] l 0 int min = r[0]; min r[0] r 0 for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    } {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    } if(min > r[i])
	    		min = r[i]; min > r[i] min r[i] r i min = r[i] min r[i] r i if(max < l[i])
	    		max = l[i]; max < l[i] max l[i] l i max = l[i] max l[i] l i int k = min - max + 1; k min - max + 1 min - max min max 1 if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k); k<0 k 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(k) System.out.println System.out System System.out k String[] args args
import java.util.Scanner;

class Main{
	public static void main (String[] args) {
		Scanner stdIn = new Scanner(System.in);
	    int n = stdIn.nextInt();
	    int m = stdIn.nextInt();
	    int[] l = new int[m];
	    int[] r = new int[m];
	    for(int i = 0;i < m;i++) {
	    	l[i] = stdIn.nextInt();
	    	r[i] = stdIn.nextInt();
	    }
	    int max = l[0];
	    int min = r[0];
	    for(int i = 1;i < m;i++) {
	    	if(min > r[i])
	    		min = r[i];
	    	if(max < l[i])
	    		max = l[i];
	    }
	    int k = min - max + 1;
	    if(k<0)
	    	System.out.println(0);
	    else
	    	System.out.println(k);
	}
}