import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
} import java.util.Comparator; Comparator java.util import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
} Main public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    } main {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder()); l new PriorityQueue<>(Comparator.reverseOrder()) PriorityQueue<Integer> r = new PriorityQueue<>(); r new PriorityQueue<>() for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        } {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        } l.add(Integer.parseInt(sc.next())) l.add l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r.add(Integer.parseInt(sc.next())) r.add r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int result = r.peek() - l.peek() + 1; result r.peek() - l.peek() + 1 r.peek() - l.peek() r.peek() r.peek r l.peek() l.peek l 1 System.out.println(result < 0 ? 0 : result) System.out.println System.out System System.out result < 0 ? 0 : result result < 0 result 0 0 result String args[] args public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
} public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
} Main
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
}