import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    }
} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    } main {
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) String[] input = scanner.nextLine().split(" "); input scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int gate_num = Integer.valueOf(input[1]); gate_num Integer.valueOf(input[1]) Integer.valueOf Integer input[1] input 1 int gate_min = Integer.MIN_VALUE; gate_min Integer.MIN_VALUE Integer Integer.MIN_VALUE int gate_max = Integer.MAX_VALUE; gate_max Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        } int i = 0; int i = 0; i 0 i < gate_num i gate_num i++ i++ i {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        } {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        } String[] allow_gate = scanner.nextLine().split(" "); allow_gate scanner.nextLine().split(" ") scanner.nextLine().split scanner.nextLine() scanner.nextLine scanner " " int min = Integer.valueOf(allow_gate[0]); min Integer.valueOf(allow_gate[0]) Integer.valueOf Integer allow_gate[0] allow_gate 0 int max = Integer.valueOf(allow_gate[1]); max Integer.valueOf(allow_gate[1]) Integer.valueOf Integer allow_gate[1] allow_gate 1 if(min > gate_min) gate_min = min; min > gate_min min gate_min gate_min = min gate_min min if(max < gate_max) gate_max = max; max < gate_max max gate_max gate_max = max gate_max max int ans = gate_max - gate_min + 1; ans gate_max - gate_min + 1 gate_max - gate_min gate_max gate_min 1 if (ans < 0) ans = 0; ans < 0 ans 0 ans = 0 ans 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] input = scanner.nextLine().split(" ");
        int gate_num = Integer.valueOf(input[1]);

        int gate_min = Integer.MIN_VALUE;
        int gate_max = Integer.MAX_VALUE;

        for(int i = 0; i < gate_num; i++) {
            String[] allow_gate = scanner.nextLine().split(" ");
            int min = Integer.valueOf(allow_gate[0]);
            int max = Integer.valueOf(allow_gate[1]);

            if(min > gate_min) gate_min = min;
            if(max < gate_max) gate_max = max;
        }
        int ans = gate_max - gate_min + 1;
        if (ans < 0) ans = 0;

        System.out.println(ans);
    }
}
