//https://atcoder.jp/contests/abc127/tasks/abc127_c

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int high = 100_000;
        int low = 0;
        for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        }
        sc.close();
        if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        }
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int high = 100_000;
        int low = 0;
        for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        }
        sc.close();
        if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int high = 100_000;
        int low = 0;
        for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        }
        sc.close();
        if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int high = 100_000;
        int low = 0;
        for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        }
        sc.close();
        if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        }
    } 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 high = 100_000; high 100_000 int low = 0; low 0 for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        } {
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if (L>low){
                low = L;
            } L>low L low {
                low = L;
            } low = L low L if (R<high){
                high = R;
            } R<high R high {
                high = R;
            } high = R high R sc.close() sc.close sc if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        } high>=low high low {
            System.out.println(high-low+1);
        } System.out.println(high-low+1) System.out.println System.out System System.out high-low+1 high-low high low 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[] args args
//https://atcoder.jp/contests/abc127/tasks/abc127_c

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int high = 100_000;
        int low = 0;
        for (int i=0;i<M;i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            if (L>low){
                low = L;
            }
            if (R<high){
                high = R;
            }
        }
        sc.close();
        if (high>=low){
            System.out.println(high-low+1);
        } else {
            System.out.println(0);
        }
    }
}