import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	}
		
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	}
		
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	} main {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int left=0; left 0 int right=n; right n for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		} int i = 0; int i = 0; i 0 i<m i m i++ i++ i {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		} {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		} int l = Integer.parseInt(sc.next()); l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(l>left) {
				left=l;
			} l>left l left {
				left=l;
			} left=l left l if(right>r) {
				right = r;
			} right>r right r {
				right = r;
			} right = r right r if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		} left>right left right {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(Math.abs(right-left)+1);
		} System.out.println(Math.abs(right-left)+1) System.out.println System.out System System.out Math.abs(right-left)+1 Math.abs(right-left) Math.abs Math right-left right left 1 String args[] args public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	}
		
} public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	}
		
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		
		int left=0;
		int right=n;
		
		for(int i = 0;i<m;i++) {
			int l = Integer.parseInt(sc.next());
			int r = Integer.parseInt(sc.next());
			if(l>left) {
				left=l;
			}
			
			if(right>r) {
				right = r;
			}
		}
		
		if(left>right) {
			System.out.println(0);
		}else {
			System.out.println(Math.abs(right-left)+1);
		}
	}
		
}