import java.util.Scanner;

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

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    }
    private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    }
    private static void show(Object answer) {
        System.out.println(answer);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = nextInt(sc);
        int M = nextInt(sc);

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    }
    private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    }
    private static void show(Object answer) {
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = nextInt(sc);
        int M = nextInt(sc);

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = nextInt(sc);
        int M = nextInt(sc);

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = nextInt(sc); N nextInt(sc) nextInt sc int M = nextInt(sc); M nextInt(sc) nextInt sc int LMax = 1; LMax 1 int RMin = N; RMin N for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         } {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         } int Li = nextInt(sc); Li nextInt(sc) nextInt sc int Ri = nextInt(sc); Ri nextInt(sc) nextInt sc if (Li > LMax) LMax = Li; Li > LMax Li LMax LMax = Li LMax Li if (Ri < RMin) RMin = Ri; Ri < RMin Ri RMin RMin = Ri RMin Ri int num = RMin - LMax + 1; num RMin - LMax + 1 RMin - LMax RMin LMax 1 show((num < 0) ? 0 : num) show (num < 0) ? 0 : num (num < 0) num 0 0 num String[] args args private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    } nextInt {
        return Integer.parseInt(sc.next());
    } return Integer.parseInt(sc.next()); Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Scanner sc sc private static void show(Object answer) {
        System.out.println(answer);
    } show {
        System.out.println(answer);
    } System.out.println(answer) System.out.println System.out System System.out answer Object answer answer public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = nextInt(sc);
        int M = nextInt(sc);

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    }
    private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    }
    private static void show(Object answer) {
        System.out.println(answer);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = nextInt(sc);
        int M = nextInt(sc);

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    }
    private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    }
    private static void show(Object answer) {
        System.out.println(answer);
    }
} Main
import java.util.Scanner;

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

        int LMax = 1;
        int RMin = N;

        for (int i = 0; i < M; i++) {
            int Li = nextInt(sc);
            int Ri = nextInt(sc);

            if (Li > LMax) LMax = Li;
            if (Ri < RMin) RMin = Ri;
         }

        int num = RMin - LMax + 1;

        show((num < 0) ? 0 : num);
    }
    private static int nextInt(Scanner sc) {
        return Integer.parseInt(sc.next());
    }
    private static void show(Object answer) {
        System.out.println(answer);
    }
}
