import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    } 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 L = 0; L 0 int R = 0; R 0 int Lmax = 0; Lmax 0 int Rmin = 100000; Rmin 100000 for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        } {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        } L = sc.nextInt() L sc.nextInt() sc.nextInt sc if (L > Lmax) {
                Lmax = L;
            } L > Lmax L Lmax {
                Lmax = L;
            } Lmax = L Lmax L R = sc.nextInt() R sc.nextInt() sc.nextInt sc if (R < Rmin) {
                Rmin = R;
            } R < Rmin R Rmin {
                Rmin = R;
            } Rmin = R Rmin R int judge = Rmin - Lmax + 1; judge Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 if (judge < 0) {
            judge = 0;
        } judge < 0 judge 0 {
            judge = 0;
        } judge = 0 judge 0 System.out.println(judge) System.out.println System.out System System.out judge sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

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

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = 0;
        int R = 0;
        int Lmax = 0;
        int Rmin = 100000;

        for (int i = 0; i < M; i++) {
            L = sc.nextInt();
            if (L > Lmax) {
                Lmax = L;
            }
            R = sc.nextInt();
            if (R < Rmin) {
                Rmin = R;
            }
        }
        int judge = Rmin - Lmax + 1;
        if (judge < 0) {
            judge = 0;
        }
        System.out.println(judge);
        sc.close();
    }
}