// 問題URL
// https://atcoder.jp/contests/abc127/tasks/abc127_c

import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
} Main public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Integer N = Integer.parseInt(scanner.next()); N Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner Integer M = Integer.parseInt(scanner.next()); M Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int LIMIT = 100000; LIMIT 100000 int[] S = new int[LIMIT+1]; S new int[LIMIT+1] LIMIT+1 LIMIT 1 for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        } {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        } Integer start = Integer.parseInt(scanner.next()); start Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner Integer end= Integer.parseInt(scanner.next()); end Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner S[start] += 1 S[start] S start 1 if(end != LIMIT) {
                S[end + 1] -= 1;
            } end != LIMIT end LIMIT {
                S[end + 1] -= 1;
            } S[end + 1] -= 1 S[end + 1] S end + 1 end 1 1 int count = 0; count 0 for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        } int i = 1; int i = 1; i 1 i <= LIMIT i LIMIT i++ i++ i {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        } {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        } S[i] += S[i-1] S[i] S i S[i-1] S i-1 i 1 if(S[i] == M) count++; S[i] == M S[i] S i M count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
} Main
// 問題URL
// https://atcoder.jp/contests/abc127/tasks/abc127_c

import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer M = Integer.parseInt(scanner.next());
        int LIMIT = 100000;
        int[] S = new int[LIMIT+1];


        for(int i = 0; i < M; i++) {
            Integer start = Integer.parseInt(scanner.next());
            Integer end= Integer.parseInt(scanner.next());
            S[start] += 1;
            if(end != LIMIT) {
                S[end + 1] -= 1;
            }
        }

        int count = 0;
        for(int i = 1; i <= LIMIT; i++) {
            S[i] += S[i-1];
            if(S[i] == M) count++;
        }

        System.out.println(count);
    }
}
