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 left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    }
} 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 left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

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

        int left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        int left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    } 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 = 0; left 0 int right = N; right N for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        } {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        } left = Math.max(sc.nextInt(), left) left Math.max(sc.nextInt(), left) Math.max Math sc.nextInt() sc.nextInt sc left right = Math.min(sc.nextInt(), right) right Math.min(sc.nextInt(), right) Math.min Math sc.nextInt() sc.nextInt sc right if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        } left <= right left right {
            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 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 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 left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

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

        int left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    }
} 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 left = 0;
        int right = N;
        for (int i = 0; i < M; i++) {
            left = Math.max(sc.nextInt(), left);
            right = Math.min(sc.nextInt(), right);
        }

        if (left <= right) {
            System.out.println(right - left + 1);
        } else {
            System.out.println(0);
        }
    }
}