import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

} import java.util.Scanner; Scanner java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Arrays; Arrays java.util import java.util.ArrayList; ArrayList java.util import java.lang.Math; Math java.lang public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    } main {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[][] lr = new int[m][2]; lr new int[m][2] m 2 for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        } {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        } lr[i][0] = sc.nextInt() lr[i][0] lr[i] lr i 0 sc.nextInt() sc.nextInt sc lr[i][1] = sc.nextInt() lr[i][1] lr[i] lr i 1 sc.nextInt() sc.nextInt sc int maxl = lr[0][0]; maxl lr[0][0] lr[0] lr 0 0 int minr = lr[0][1]; minr lr[0][1] lr[0] lr 0 1 for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        } {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        } if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            } maxl < lr[i][0] maxl lr[i][0] lr[i] lr i 0 {
                maxl = lr[i][0];
            } maxl = lr[i][0] maxl lr[i][0] lr[i] lr i 0 if (minr > lr[i][1]) {
                minr = lr[i][1];
            } minr > lr[i][1] minr lr[i][1] lr[i] lr i 1 {
                minr = lr[i][1];
            } minr = lr[i][1] minr lr[i][1] lr[i] lr i 1 if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        } minr - maxl > 0 minr - maxl minr maxl 0 {
            System.out.println(minr - maxl + 1);
        } System.out.println(minr - maxl + 1) System.out.println System.out System System.out minr - maxl + 1 minr - maxl minr maxl 1 if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        } minr - maxl == 0 minr - maxl minr maxl 0 {
            System.out.println(1);
        } System.out.println(1) System.out.println System.out System System.out 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

} public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

} Main
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] lr = new int[m][2];
        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        int maxl = lr[0][0];
        int minr = lr[0][1];
        for (int i = 1; i < m; i++) {
            if (maxl < lr[i][0]) {
                maxl = lr[i][0];
            }
            if (minr > lr[i][1]) {
                minr = lr[i][1];
            }
        }
        if (minr - maxl > 0) {
            System.out.println(minr - maxl + 1);
        } else if (minr - maxl == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

}
