import java.util.*;

public class Main {
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    }
} import java.util.*; util.* java public class Main {
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    }
} Main static long mod = 1000000007; mod 1000000007 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    } main {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long m = sc.nextLong(); m sc.nextLong() sc.nextLong sc int min = 0; min 0 int max = 100000; max 100000 for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } int i = 0; int i = 0; i 0 i < m i m ++i ++i i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc min = Math.max(min, l) min Math.max(min, l) Math.max Math min l max = Math.min(max, r) max Math.min(max, r) Math.min Math max r System.out.println(Math.min(n, Math.max(0, max - min + 1))) System.out.println System.out System System.out Math.min(n, Math.max(0, max - min + 1)) Math.min Math n Math.max(0, max - min + 1) Math.max Math 0 max - min + 1 max - min max min 1 String[] args args public class Main {
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    }
} public class Main {
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    }
} Main
import java.util.*;

public class Main {
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        int min = 0;
        int max = 100000;
        for (int i = 0; i < m; ++i) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            min = Math.max(min, l);
            max = Math.min(max, r);
        }
        System.out.println(Math.min(n, Math.max(0, max - min + 1)));
    }
}
