import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    } main {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int M = Integer.parseInt(sc.next()); M Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int maxStart = 0; maxStart 0 int minEnd = 1000000; minEnd 1000000 for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        } {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        } int start = Integer.parseInt(sc.next()); start Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int end = Integer.parseInt(sc.next()); end Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc maxStart = Math.max(maxStart, start) maxStart Math.max(maxStart, start) Math.max Math maxStart start minEnd = Math.min(minEnd, end) minEnd Math.min(minEnd, end) Math.min Math minEnd end out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0") out.println out minEnd >= maxStart ? minEnd - maxStart + 1 : "0" minEnd >= maxStart minEnd maxStart minEnd - maxStart + 1 minEnd - maxStart minEnd maxStart 1 "0" out.flush() out.flush out String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    }
} Main
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int maxStart = 0;
        int minEnd = 1000000;
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            maxStart = Math.max(maxStart, start);
            minEnd = Math.min(minEnd, end);
        }
        
        out.println(minEnd >= maxStart ? minEnd - maxStart + 1 : "0");
        
        out.flush();
    }
}