import java.util.*;
public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    }

} import java.util.*; util.* java public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[][] arr = new int[m][2]; arr new int[m][2] m 2 for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        } {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        } arr[i][0] = sc.nextInt() arr[i][0] arr[i] arr i 0 sc.nextInt() sc.nextInt sc arr[i][1] = sc.nextInt() arr[i][1] arr[i] arr i 1 sc.nextInt() sc.nextInt sc int start = arr[0][0]; start arr[0][0] arr[0] arr 0 0 int end = arr[0][1]; end arr[0][1] arr[0] arr 0 1 for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        } {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        } start = Math.max(start, arr[i][0]) start Math.max(start, arr[i][0]) Math.max Math start arr[i][0] arr[i] arr i 0 end = Math.min(end, arr[i][1]) end Math.min(end, arr[i][1]) Math.min Math end arr[i][1] arr[i] arr i 1 if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0); end - start >= 0 end - start end start 0 System.out.println(end - start + 1) System.out.println System.out System System.out end - start + 1 end - start end start 1 System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    }

} public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    }

} Main
import java.util.*;
public class Main { 

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for(int i = 0; i < m; i++) {
           arr[i][0] = sc.nextInt();
           arr[i][1] = sc.nextInt();
        }
        int start = arr[0][0];
        int end = arr[0][1];
        for(int i = 1; i < m; i++) {
            start = Math.max(start, arr[i][0]);
            end = Math.min(end, arr[i][1]);
        }
        if(end - start >= 0)
            System.out.println(end - start + 1);
        else
            System.out.println(0);
    }

}