

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
} import java.io.*; io.* java import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java import java.util.Stack; Stack java.util public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
} Main public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); out new PrintWriter (new BufferedOutputStream(System.out)) static int mod = (int) (1e9+7); mod (int) (1e9+7) 1e9 7 static long cf = 998244353; cf 998244353 static final int MAX = (int) 1e6; MAX (int) 1e6 public static List<Pair>[] edges; edges public static int[][] parent; parent public static int col = 20; col 20 public static long[] Bit; Bit public static long[] fac fac inv; inv public  static int[] prime; prime public static long[] dp; dp public static FastReader sc = new FastReader(); sc new FastReader() public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	} main {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	} int n = sc.nextInt() n sc.nextInt() sc.nextInt sc m=sc.nextInt(); m sc.nextInt() sc.nextInt sc int l =1 l 1 r=n; r n for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		} int i=0; int i=0; i 0 i<m i m ++i ++i i {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		} {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		} l = Math.max(l, sc.nextInt()) l Math.max(l, sc.nextInt()) Math.max Math l sc.nextInt() sc.nextInt sc r = Math.min(r, sc.nextInt()) r Math.min(r, sc.nextInt()) Math.min Math r sc.nextInt() sc.nextInt sc out.print(Math.max(0, r-l+1)) out.print out Math.max(0, r-l+1) Math.max Math 0 r-l+1 r-l r l 1 out.close() out.close out String[] args args public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	} FastReader BufferedReader br; br StringTokenizer root; root public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		} FastReader {
			br = new BufferedReader(new InputStreamReader(System.in));
		} br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		} next {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		} while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			} root == null || !root.hasMoreTokens() root == null root null !root.hasMoreTokens() root.hasMoreTokens() root.hasMoreTokens root {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			} try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				} catch (Exception r) {
					r.printStackTrace();
				} Exception r {
					r.printStackTrace();
				} r.printStackTrace() r.printStackTrace r {
					root = new StringTokenizer(br.readLine());
				} root = new StringTokenizer(br.readLine()) root new StringTokenizer(br.readLine()) return root.nextToken(); root.nextToken() root.nextToken root int nextInt() {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next double nextDouble() {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next long nextLong() {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		} nextLine {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		} String str = ""; str "" try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			} catch (Exception r) {
				r.printStackTrace();
			} Exception r {
				r.printStackTrace();
			} r.printStackTrace() r.printStackTrace r {
				str = br.readLine();
			} str = br.readLine() str br.readLine() br.readLine br return str; str static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	} Pair int x; x int y; y Pair(int x,int y){
			this.x = x;
			this.y = y;
		} Pair {
			this.x = x;
			this.y = y;
		} this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
} public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
} Main


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7);
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Pair>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt(),m=sc.nextInt();
		int l =1,r=n;
		for(int i=0;i<m;++i) {
			l = Math.max(l, sc.nextInt());
			r = Math.min(r, sc.nextInt());
		}
	 out.print(Math.max(0, r-l+1));
		 
		out.close();
	}

	
	static class Pair{
		int x;
		int y;
		Pair(int x,int y){
			this.x = x;
			this.y = y;
		}
	}
	
}