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

public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    }


} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    }


} Main public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    } main {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    } InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        } catch (IOException e) {

        } IOException e {

        } {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } String strData = br.readLine(); strData br.readLine() br.readLine br String strDat[] = strData.split(" ", -1); strDat strData.split(" ", -1) strData.split strData " " -1 1 int intCard = Integer.parseInt(strDat[0]); intCard Integer.parseInt(strDat[0]) Integer.parseInt Integer strDat[0] strDat 0 int intGate = Integer.parseInt(strDat[1]); intGate Integer.parseInt(strDat[1]) Integer.parseInt Integer strDat[1] strDat 1 int intL[] = new int [intGate]; intL new int [intGate] intGate int intR[] = new int [intGate]; intR new int [intGate] intGate int intSt; intSt int intEd; intEd intSt = 0 intSt 0 intEd = intCard intEd intCard for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		} int i=0 ; int i=0 ; i 0 i<intGate i intGate i++ i++ i {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		} {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		} strData = br.readLine() strData br.readLine() br.readLine br strDat = strData.split(" ", -1) strDat strData.split(" ", -1) strData.split strData " " -1 1 intL[i] = Integer.parseInt(strDat[0]) intL[i] intL i Integer.parseInt(strDat[0]) Integer.parseInt Integer strDat[0] strDat 0 intR[i] = Integer.parseInt(strDat[1]) intR[i] intR i Integer.parseInt(strDat[1]) Integer.parseInt Integer strDat[1] strDat 1 if (intL[i] > intSt) intSt = intL[i]; intL[i] > intSt intL[i] intL i intSt intSt = intL[i] intSt intL[i] intL i if (intR[i] < intEd) intEd = intR[i]; intR[i] < intEd intR[i] intR i intEd intEd = intR[i] intEd intR[i] intR i int ans = 0; ans 0 ans = intEd - intSt+ 1 ans intEd - intSt+ 1 intEd - intSt intEd intSt 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 out.flush() out.flush out String[] args args public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    }


} public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    }


} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        PrintWriter out = new PrintWriter(System.out);

        try {
    		String strData = br.readLine();
    		String strDat[] = strData.split(" ", -1);

    		int intCard = Integer.parseInt(strDat[0]);
    		int intGate = Integer.parseInt(strDat[1]);

    		int intL[] = new int [intGate];
    		int intR[] = new int [intGate];

    		int intSt;
    		int intEd;

    		intSt = 0;
    		intEd = intCard;

    		for (int i=0 ; i<intGate ; i++) {
        		strData = br.readLine();
        		strDat = strData.split(" ", -1);

        		intL[i] = Integer.parseInt(strDat[0]);
        		intR[i] = Integer.parseInt(strDat[1]);

        		if (intL[i] > intSt) intSt = intL[i];
        		if (intR[i] < intEd) intEd = intR[i];

    		}
    		int ans = 0;

//    		for (int i=0 ; i<intCard ; i++) {
//    		for (int i = intSt-1 ; i <= intEd-1 ; i++) {
//    			int j;
//	    		for (j=0 ; j<intGate ; j++) {
//	    			if (!(intL[j] <= i+1 && i+1 <= intR[j])) break;
//	    		}
//
//	    		if (j == intGate) ans ++;
//    		}

    		ans = intEd - intSt+ 1;
    		if (ans < 0) ans = 0;

    		System.out.println(ans );

    		out.flush();


        } catch (IOException e) {

        }


    }


}