import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    } 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 min = sc.nextInt(); min sc.nextInt() sc.nextInt sc int max = sc.nextInt(); max sc.nextInt() sc.nextInt sc m-- m while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        } m-- > 0 m-- m 0 {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        } min = Math.max(min, sc.nextInt()) min Math.max(min, sc.nextInt()) Math.max Math min sc.nextInt() sc.nextInt sc max = Math.min(max, sc.nextInt()) max Math.min(max, sc.nextInt()) Math.min Math max sc.nextInt() sc.nextInt sc if (min > max) {
            System.out.println(0);
            return;
        } min > max min max {
            System.out.println(0);
            return;
        } System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(max - min + 1) System.out.println System.out System System.out max - min + 1 max - min max min 1 String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int min = sc.nextInt();
        int max = sc.nextInt();
        m--;
        while (m-- > 0) {
            min = Math.max(min, sc.nextInt());
            max = Math.min(max, sc.nextInt());
        }
        
        if (min > max) {
            System.out.println(0);
            return;
        }
        System.out.println(max - min + 1);
    }
}
