import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    }
} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    }
} Main private static long n; n public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    } main {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    } try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        } {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        } BufferedInputStream in = new BufferedInputStream(System.in) BufferedInputStream in = new BufferedInputStream(System.in) new BufferedInputStream(System.in) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) new PrintWriter(new BufferedOutputStream(System.out)) Scanner sc = new Scanner(in); sc new Scanner(in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int lm = -1; lm -1 1 int rm = Integer.MAX_VALUE; rm Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            } {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            } lm = Math.max(lm, sc.nextInt()) lm Math.max(lm, sc.nextInt()) Math.max Math lm sc.nextInt() sc.nextInt sc rm = Math.min(rm, sc.nextInt()) rm Math.min(rm, sc.nextInt()) Math.min Math rm sc.nextInt() sc.nextInt sc out.println(lm > rm ? 0 : rm - lm + 1) out.println out lm > rm ? 0 : rm - lm + 1 lm > rm lm rm 0 rm - lm + 1 rm - lm rm lm 1 String[] args args public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    }
} public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    }
} Main
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    private static long n;

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 18:24-

            int n = sc.nextInt();
            int m = sc.nextInt();
            int lm = -1;
            int rm = Integer.MAX_VALUE;
            
            for (int i = 0; i < m; i++) {
                lm = Math.max(lm, sc.nextInt());
                rm = Math.min(rm, sc.nextInt());
            }

            out.println(lm > rm ? 0 : rm - lm + 1);
        }
    }
}
