import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}
   import java.io.PrintStream; PrintStream java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
} Main static final PrintStream out = System.out; out System.out System System.out static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static final long Mod = 1000_000_007L; Mod 1000_000_007L public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	} main {
		Main main = new Main();
		main.solve();
		System.exit(0);
	} Main main = new Main(); main new Main() main.solve() main.solve main System.exit(0) System.exit System 0 String[] args args void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	} solve {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	} int n = nextInt(); n nextInt() nextInt int m = nextInt(); m nextInt() nextInt int maxL = 0 maxL 0 minR = 100010; minR 100010 for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		} {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		} int L = nextInt(); L nextInt() nextInt int R = nextInt(); R nextInt() nextInt maxL = Math.max(maxL,L) maxL Math.max(maxL,L) Math.max Math maxL L minR = Math.min(minR,R) minR Math.min(minR,R) Math.min Math minR R if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1); maxL > minR maxL minR out.println(0) out.println out 0 out.println(minR - maxL + 1) out.println out minR - maxL + 1 minR - maxL minR maxL 1 private static int nextInt() {
		return Integer.parseInt(next());
	} nextInt {
		return Integer.parseInt(next());
	} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next private static long nextLong() {
		return Long.parseLong(next());
	} nextLong {
		return Long.parseLong(next());
	} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next private static String next() {
		return sc.next();
	} next {
		return sc.next();
	} return sc.next(); sc.next() sc.next sc public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
} public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
} Main
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}
	void solve() {
		int n = nextInt();
		int m = nextInt();
		int maxL = 0,minR = 100010;
		for(int i=0;i<m;i++) {
			int L = nextInt();
			int R = nextInt();
			maxL = Math.max(maxL,L);
			minR = Math.min(minR,R);
		}

		if(maxL > minR)out.println(0);
		else out.println(minR - maxL + 1);
	}
  
	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}
  