import java.util.*;
import java.util.Scanner;
import java.lang.*;

public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    }
} import java.util.*; util.* java import java.util.Scanner; Scanner java.util import java.lang.*; lang.* java public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    }
} Main public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    } main {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String input = scanner.nextLine(); input scanner.nextLine() scanner.nextLine scanner String[] inputs = input.split(" "); inputs input.split(" ") input.split input " " int N = Integer.parseInt(inputs[0]); N Integer.parseInt(inputs[0]) Integer.parseInt Integer inputs[0] inputs 0 int M = Integer.parseInt(inputs[1]); M Integer.parseInt(inputs[1]) Integer.parseInt Integer inputs[1] inputs 1 int startPos = 0; startPos 0 int endPos = 100000; endPos 100000 Map<Integer,Integer> LR = new LinkedHashMap(); LR new LinkedHashMap() for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            } {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            } String strLR = scanner.nextLine(); strLR scanner.nextLine() scanner.nextLine scanner String[] arrayLR = strLR.split(" "); arrayLR strLR.split(" ") strLR.split strLR " " int L = Integer.parseInt(arrayLR[0]); L Integer.parseInt(arrayLR[0]) Integer.parseInt Integer arrayLR[0] arrayLR 0 int R = Integer.parseInt(arrayLR[1]); R Integer.parseInt(arrayLR[1]) Integer.parseInt Integer arrayLR[1] arrayLR 1 if (startPos <= L) {
                    startPos = L;
                } startPos <= L startPos L {
                    startPos = L;
                } startPos = L startPos L if (endPos >= R) {
                    endPos = R;
                } endPos >= R endPos R {
                    endPos = R;
                } endPos = R endPos R if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            } endPos >= startPos endPos startPos {
                System.out.println(endPos - startPos + 1);
            } System.out.println(endPos - startPos + 1) System.out.println System.out System System.out endPos - startPos + 1 endPos - startPos endPos startPos 1 {
                System.out.println(0);
            } System.out.println(0) System.out.println System.out System System.out 0 scanner.close() scanner.close scanner String[] args args public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    }
} public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    }
} Main
import java.util.*;
import java.util.Scanner;
import java.lang.*;

public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int N = Integer.parseInt(inputs[0]);
            int M = Integer.parseInt(inputs[1]);

            int startPos = 0;
            int endPos = 100000;

            Map<Integer,Integer> LR = new LinkedHashMap();
            for (int i = 0;i < M;i++) {
                String strLR = scanner.nextLine();
                String[] arrayLR = strLR.split(" ");

                 int L = Integer.parseInt(arrayLR[0]);
                 int R = Integer.parseInt(arrayLR[1]);

                if (startPos <= L) {
                    startPos = L;
                }
                
                if (endPos >= R) {
                    endPos = R;
                }
            }
        

            if (endPos >= startPos) {
                System.out.println(endPos - startPos + 1);
            } else {
                System.out.println(0);
            }
            
            scanner.close();
    }
}