import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner 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 maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    } 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 maxL = 0; maxL 0 int minr = 100000; minr 100000 for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int 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 {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int 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 int ans = 0; ans 0 if (minr - maxL >= 0)
            ans = minr - maxL + 1; minr - maxL >= 0 minr - maxL minr maxL 0 ans = minr - maxL + 1 ans minr - maxL + 1 minr - maxL minr maxL 1 System.out.println(ans) System.out.println System.out System System.out ans 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 maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int maxL = 0;
        int minr = 100000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            maxL = Math.max(maxL, l);
            minr = Math.min(minr, r);
        }
        
        int ans = 0;
        if (minr - maxL >= 0)
            ans = minr - maxL + 1;
        
        System.out.println(ans);
    }
}