import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int L[] = new int [m];
        int R[] = new int [m];
        int maxL = 1; int minR = n;
        for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        }

        System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 );
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int L[] = new int [m];
        int R[] = new int [m];
        int maxL = 1; int minR = n;
        for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        }

        System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 );
    }
} Main public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int L[] = new int [m];
        int R[] = new int [m];
        int maxL = 1; int minR = n;
        for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        }

        System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 );
    } main {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int L[] = new int [m];
        int R[] = new int [m];
        int maxL = 1; int minR = n;
        for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        }

        System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 );
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int m = stdIn.nextInt(); m stdIn.nextInt() stdIn.nextInt stdIn int L[] = new int [m]; L new int [m] m int R[] = new int [m]; R new int [m] m int maxL = 1; maxL 1 int minR = n; minR n for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        } {
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        } L[i] = stdIn.nextInt() L[i] L i stdIn.nextInt() stdIn.nextInt stdIn R[i] = stdIn.nextInt() R[i] R i stdIn.nextInt() stdIn.nextInt stdIn if(maxL < L[i]) maxL = L[i]; maxL < L[i] maxL L[i] L i maxL = L[i] maxL L[i] L i if(minR > R[i]) minR = R[i]; minR > R[i] minR R[i] R i minR = R[i] minR R[i] R i System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 ) System.out.println System.out System System.out minR-maxL+1 >= 0 ? minR-maxL+1 : 0 minR-maxL+1 >= 0 minR-maxL+1 minR-maxL minR maxL 1 0 minR-maxL+1 minR-maxL minR maxL 1 0 String[] args args
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        int L[] = new int [m];
        int R[] = new int [m];
        int maxL = 1; int minR = n;
        for(int i = 0; i < m; i++){
            L[i] = stdIn.nextInt();
            R[i] = stdIn.nextInt();
            if(maxL < L[i]) maxL = L[i];
            if(minR > R[i]) minR = R[i];
        }

        System.out.println(minR-maxL+1 >= 0 ? minR-maxL+1 : 0 );
    }
}