import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] in = br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(in[0]); n Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 int m = Integer.parseInt(in[1]); m Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 int l0 = 0; l0 0 int r0 = 1000000000; r0 1000000000 for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        } {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        } in = br.readLine().split(" ") in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int l = Integer.parseInt(in[0]); l Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 int r = Integer.parseInt(in[1]); r Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 l0 = Math.max(l0, l) l0 Math.max(l0, l) Math.max Math l0 l r0 = Math.min(r0, r) r0 Math.min(r0, r) Math.min Math r0 r System.out.println(r0 >= l0? r0 - l0 + 1 : 0) System.out.println System.out System System.out r0 >= l0? r0 - l0 + 1 : 0 r0 >= l0 r0 l0 r0 - l0 + 1 r0 - l0 r0 l0 1 0 br.close() br.close br String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] in = br.readLine().split(" ");
        int n = Integer.parseInt(in[0]);
        int m = Integer.parseInt(in[1]);

        int l0 = 0;
        int r0 = 1000000000;
        for(int i = 0; i < m; i++) {
            in = br.readLine().split(" ");
            int l = Integer.parseInt(in[0]);
            int r = Integer.parseInt(in[1]);
            l0 = Math.max(l0, l);
            r0 = Math.min(r0, r);
        }

        System.out.println(r0 >= l0? r0 - l0 + 1 : 0);

        br.close();
    }
}