import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

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


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    } main {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String nm =  sc.nextLine(); nm sc.nextLine() sc.nextLine sc int n = Integer.parseInt(nm.split(" ")[0]); n Integer.parseInt(nm.split(" ")[0]) Integer.parseInt Integer nm.split(" ")[0] nm.split(" ") nm.split nm " " 0 int m = Integer.parseInt(nm.split(" ")[1]); m Integer.parseInt(nm.split(" ")[1]) Integer.parseInt Integer nm.split(" ")[1] nm.split(" ") nm.split nm " " 1 int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        } {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        } String lr = sc.nextLine(); lr sc.nextLine() sc.nextLine sc l[i] = Integer.parseInt(lr.split(" ")[0]) l[i] l i Integer.parseInt(lr.split(" ")[0]) Integer.parseInt Integer lr.split(" ")[0] lr.split(" ") lr.split lr " " 0 r[i] = Integer.parseInt(lr.split(" ")[1]) r[i] r i Integer.parseInt(lr.split(" ")[1]) Integer.parseInt Integer lr.split(" ")[1] lr.split(" ") lr.split lr " " 1 int min min max; max min = 1000000 min 1000000 max = 0 max 0 for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        } {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        } min = Math.min(min, r[i]) min Math.min(min, r[i]) Math.min Math min r[i] r i max = Math.max(max, l[i]) max Math.max(max, l[i]) Math.max Math max l[i] l i if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        } min - max >= 0 min - max min max 0 {
            System.out.println(min - max + 1);
        } System.out.println(min - max + 1) System.out.println System.out System System.out min - max + 1 min - max min max 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 return; String[] args args public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    }
} public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    }
} Main
import java.util.*;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String nm =  sc.nextLine();
        int n = Integer.parseInt(nm.split(" ")[0]);
        int m = Integer.parseInt(nm.split(" ")[1]);

        int[] l = new int[m];
        int[] r = new int[m];

        for (int i = 0; i < m; i++) {
            String lr = sc.nextLine();
            l[i] = Integer.parseInt(lr.split(" ")[0]);
            r[i] = Integer.parseInt(lr.split(" ")[1]);

        }

        int min, max;
        min = 1000000;
        max = 0;

        for (int i = 0; i < m; i++) {
            min = Math.min(min, r[i]);
            max = Math.max(max, l[i]);
        }

        if (min - max >= 0) {
            System.out.println(min - max + 1);
        } else {
            System.out.println(0);
        }

        return;
    }
}
