import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import static java.util.Collections.sort;
import static java.util.Collections.reverseOrder;

public class Main {
  	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import static java.util.Collections.sort; import static java.util.Collections.sort; import static java.util.Collections.sort; import static java.util.Collections.reverseOrder; import static java.util.Collections.reverseOrder; import static java.util.Collections.reverseOrder; public class Main {
  	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    } main {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int card = in.nextInt(); card in.nextInt() in.nextInt in int gate = in.nextInt(); gate in.nextInt() in.nextInt in List<Integer> min = new ArrayList<Integer>(gate); min new ArrayList<Integer>(gate) List<Integer> max = new ArrayList<Integer>(gate); max new ArrayList<Integer>(gate) int cch; cch for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        } int i = 0; int i = 0; i 0 i < gate i gate i++ i++ i {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        } {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        } for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            } int j = 0; int j = 0; j 0 j < 2 j 2 j++ j++ j {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            } {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            } cch = in.nextInt() cch in.nextInt() in.nextInt in if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                } j == 0 j 0 {
                    min.add(cch);
                } min.add(cch) min.add min cch {
                    max.add(cch);
                } max.add(cch) max.add max cch in.close() in.close in sort(max) sort max sort(min, reverseOrder()) sort min reverseOrder() reverseOrder int ans = max.get(0) - min.get(0) + 1; ans max.get(0) - min.get(0) + 1 max.get(0) - min.get(0) max.get(0) max.get max 0 min.get(0) min.get min 0 1 if (ans < 0) ans = 0; ans < 0 ans 0 ans = 0 ans 0 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 in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    }
} public class Main {
  	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import static java.util.Collections.sort;
import static java.util.Collections.reverseOrder;

public class Main {
  	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int card = in.nextInt();
        int gate = in.nextInt();
        List<Integer> min = new ArrayList<Integer>(gate);
        List<Integer> max = new ArrayList<Integer>(gate);
        int cch;
        for (int i = 0; i < gate; i++) {
            for (int j = 0; j < 2; j++) {
                cch = in.nextInt();
                if (j == 0) {
                    min.add(cch);
                } else {
                    max.add(cch);
                }
            }
        }
        in.close();
        sort(max);
        sort(min, reverseOrder());
        int ans = max.get(0) - min.get(0) + 1;
        if (ans < 0) ans = 0;
        System.out.println(ans);

    }
}