import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int maxL = 0; maxL 0 int minR = 100001; minR 100001 for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        } {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        } maxL = Math.max(maxL, Integer.parseInt(sc.next())) maxL Math.max(maxL, Integer.parseInt(sc.next())) Math.max Math maxL Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc minR = Math.min(minR, Integer.parseInt(sc.next())) minR Math.min(minR, Integer.parseInt(sc.next())) Math.min Math minR Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc System.out.println((minR >= maxL) ? minR - maxL + 1 : 0) System.out.println System.out System System.out (minR >= maxL) ? minR - maxL + 1 : 0 (minR >= maxL) minR maxL minR - maxL + 1 minR - maxL minR maxL 1 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        int maxL = 0;
        int minR = 100001;

        for (int i = 0; i < m; i++) {
            maxL = Math.max(maxL, Integer.parseInt(sc.next()));
            minR = Math.min(minR, Integer.parseInt(sc.next()));
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
}
