import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        }
} import java.util.*; util.* java public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        }
} Main public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        } main {
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Map hs = new HashMap(); hs new HashMap() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[][] l = new int[2][m]; l new int[2][m] 2 m for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                } int i = 0 ; int i = 0 ; i 0 i < m i m i++ i++ i {
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                } {
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                } for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        } int j = 0 ; int j = 0 ; j 0 j < 2 j 2 j++ j++ j {
                                l[j][i] = sc.nextInt();
                        } {
                                l[j][i] = sc.nextInt();
                        } l[j][i] = sc.nextInt() l[j][i] l[j] l j i sc.nextInt() sc.nextInt sc for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                } int i = 0 ; int i = 0 ; i 0 i < 2 i 2 i++ i++ i {
                        Arrays.sort(l[i]);
                } {
                        Arrays.sort(l[i]);
                } Arrays.sort(l[i]) Arrays.sort Arrays l[i] l i sc.close() sc.close sc System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1)) System.out.println System.out System System.out Math.max(0 , l[1][0] - l[0][m - 1] + 1) Math.max Math 0 l[1][0] - l[0][m - 1] + 1 l[1][0] - l[0][m - 1] l[1][0] l[1] l 1 0 l[0][m - 1] l[0] l 0 m - 1 m 1 1 String[] args args public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        }
} public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        }
} Main
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[][] l = new int[2][m];
                for(int i = 0 ; i < m ; i++){
                        for(int j = 0 ; j < 2 ; j++){
                                l[j][i] = sc.nextInt();
                        }
                }
                for(int i = 0 ; i < 2 ; i++){
                        Arrays.sort(l[i]);
                }
                sc.close();
                System.out.println(Math.max(0 , l[1][0] - l[0][m - 1] + 1));
        }
}