import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    }

} import java.util.Scanner; Scanner 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 min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    } 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 = 0; min 0 int max = 1_000_000; max 1_000_000 for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = 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 > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if (l > min) {
                min = l;
            } l > min l min {
                min = l;
            } min = l min l if (r < max) {
                max = r;
            } r < max r max {
                max = r;
            } max = r max r sc.close() sc.close sc int ans; ans if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        } max < min max min {
            ans = 0;
        } ans = 0 ans 0 {
            ans = max - min + 1;
        } ans = max - min + 1 ans max - min + 1 max - min max min 1 System.out.println(ans) System.out.println System.out System System.out ans 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 min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int min = 0;
        int max = 1_000_000;
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (l > min) {
                min = l;
            }
            if (r < max) {
                max = r;
            }
        }
        sc.close();

        int ans;
        if (max < min) {
            ans = 0;
        } else {
            ans = max - min + 1;
        }
        System.out.println(ans);
    }

}
