import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 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 l l r; r int maxL = 0; maxL 0 int minR = Integer.MAX_VALUE; minR Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        } int i = 0; int i = 0; i 0 i< m i m i++ i++ i {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        } {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        } l = sc.nextInt() l sc.nextInt() sc.nextInt sc r = sc.nextInt() r sc.nextInt() sc.nextInt sc maxL = Math.max(maxL, l) maxL Math.max(maxL, l) Math.max Math maxL l minR = Math.min(minR, r) minR Math.min(minR, r) Math.min Math minR r if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        } minR < maxL minR maxL {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(minR - maxL + 1);
        } System.out.println(minR - maxL + 1) System.out.println System.out System System.out minR - maxL + 1 minR - maxL minR maxL 1 String args[] args public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l,r;
        int maxL = 0;
        int minR = Integer.MAX_VALUE;
        for (int i = 0; i< m;i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            maxL = Math.max(maxL, l);
            minR = Math.min(minR, r);
        }
        
        if (minR < maxL) {
            System.out.println(0);
        } else {
            System.out.println(minR - maxL + 1);
        }
    }
}