import java.util.*;

class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        }
    }
} import java.util.*; util.* java class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        }
    }
} Main public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+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 left = 1; left 1 int right = N; right N for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        } 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 > left)left=L;
            if(R < right)right=R;
        } {
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(L > left)left=L; L > left L left left=L left L if(R < right)right=R; R < right R right right=R right R if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        } right < left right left {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(right-left+1);
        } System.out.println(right-left+1) System.out.println System.out System System.out right-left+1 right-left right left 1 String argv[] argv
import java.util.*;

class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int left = 1;
        int right = N;
        for(int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if(L > left)left=L;
            if(R < right)right=R;
        }
        if(right < left){
            System.out.println(0);
        }
        else{
            System.out.println(right-left+1);
        }
    }
}