import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();

        int min = 1;
        int max = N;
        for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        }

        System.out.println(max-min+1);
    }
} import java.util.*; util.* java class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int min = 1;
        int max = N;
        for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        }

        System.out.println(max-min+1);
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int min = 1;
        int max = N;
        for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        }

        System.out.println(max-min+1);
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        int min = 1;
        int max = N;
        for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        }

        System.out.println(max-min+1);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int min = 1; min 1 int max = N; max N for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        } {
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(L > min && L <= max) min = L; L > min && L <= max L > min L min L <= max L max min = L min L if(L > min && L > max) {
                System.out.println(0);
                return;
            } L > min && L > max L > min L min L > max L max {
                System.out.println(0);
                return;
            } System.out.println(0) System.out.println System.out System System.out 0 return; if(R < max && R >= min) max = R; R < max && R >= min R < max R max R >= min R min max = R max R if(R < max && R < min) {
                System.out.println(0);
                return;
            } R < max && R < min R < max R max R < min R min {
                System.out.println(0);
                return;
            } System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 1 String args[] args
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();

        int min = 1;
        int max = N;
        for(int i=0; i<M; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > min && L <= max) min = L;
            if(L > min && L > max) {
                System.out.println(0);
                return;
            }
            if(R < max && R >= min) max = R;
            if(R < max && R < min) {
                System.out.println(0);
                return;
            }
        }

        System.out.println(max-min+1);
    }
}