import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int m = scan.nextInt(); m scan.nextInt() scan.nextInt scan int[][] lr = new int[m][2]; lr new int[m][2] m 2 for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        } {
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        } for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < 2 j 2 j++ j++ j {
                lr[i][j] = scan.nextInt();
            } {
                lr[i][j] = scan.nextInt();
            } lr[i][j] = scan.nextInt() lr[i][j] lr[i] lr i j scan.nextInt() scan.nextInt scan boolean b = true; b true int out = 0; out 0 int min = lr[0][0]; min lr[0][0] lr[0] lr 0 0 int max = lr[0][1]; max lr[0][1] lr[0] lr 0 1 for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        } {
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        } if(lr[i][0] > min){
                min = lr[i][0];
            } lr[i][0] > min lr[i][0] lr[i] lr i 0 min {
                min = lr[i][0];
            } min = lr[i][0] min lr[i][0] lr[i] lr i 0 for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        } int i = 1; int i = 1; i 1 i < m i m i++ i++ i {
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        } {
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        } if(lr[i][1] < max){
                max = lr[i][1];
            } lr[i][1] < max lr[i][1] lr[i] lr i 1 max {
                max = lr[i][1];
            } max = lr[i][1] max lr[i][1] lr[i] lr i 1 for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        } {
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        } if(b){
                out++;
            } b {
                out++;
            } out++ out b = true b true System.out.println(out) System.out.println System.out System System.out out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int[][] lr = new int[m][2];
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                lr[i][j] = scan.nextInt();
            }
        }
        boolean b = true;
        int out = 0;
        int min = lr[0][0];
        int max = lr[0][1];
        for(int i = 1; i < m; i++){
            if(lr[i][0] > min){
                min = lr[i][0];
            }
        }
        for(int i = 1; i < m; i++){
            if(lr[i][1] < max){
                max = lr[i][1];
            }
        }
        for(int i = 1; i <= n; i++){
            a : for(int j = 0; j < m; j++){
                if(min > i || max < i){
                    b = false;
                    break a;
                }
            }
            if(b){
                out++;
            }
            b = true;
        }
        System.out.println(out);
    }
}