import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    } main {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int card = scanner.nextInt(); card scanner.nextInt() scanner.nextInt scanner int gate = scanner.nextInt(); gate scanner.nextInt() scanner.nextInt scanner int l = 0 l 0 r = Integer.MAX_VALUE r Integer.MAX_VALUE Integer Integer.MAX_VALUE tmpr = 0 tmpr 0 tmpl = 0; tmpl 0 for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        } int i=0; int i=0; i 0 i < gate i gate i++ i++ i {
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        } {
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        } tmpl = scanner.nextInt() tmpl scanner.nextInt() scanner.nextInt scanner tmpr = scanner.nextInt() tmpr scanner.nextInt() scanner.nextInt scanner l = (l > tmpl ? l : tmpl) l (l > tmpl ? l : tmpl) l > tmpl l tmpl l tmpl r = (r < tmpr ? r : tmpr) r (r < tmpr ? r : tmpr) r < tmpr r tmpr r tmpr int open  = r-l+1; open r-l+1 r-l r l 1 open = open <= 0 ? 0 : open open open <= 0 ? 0 : open open <= 0 open 0 0 open System.out.println(open) System.out.println System.out System System.out open String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int card = scanner.nextInt();
        int gate = scanner.nextInt();
        
        int l = 0,r = Integer.MAX_VALUE,tmpr = 0,tmpl = 0;
        for(int i=0;i < gate; i++){
            tmpl = scanner.nextInt();
            tmpr = scanner.nextInt();
            l = (l > tmpl ? l : tmpl);
            r = (r < tmpr ? r : tmpr);
        }
        
        int open  = r-l+1;
        open = open <= 0 ? 0 : open; 
        System.out.println(open);
    }
}
