import java.util.Scanner;

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

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