import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
        int min = 0;
        int max = 0;

        min = Integer.parseInt(sc.next());
        max = Integer.parseInt(sc.next());

        for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        }

        int counter = 0;
        for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        }
        System.out.println(counter);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
        int min = 0;
        int max = 0;

        min = Integer.parseInt(sc.next());
        max = Integer.parseInt(sc.next());

        for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        }

        int counter = 0;
        for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        }
        System.out.println(counter);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
        int min = 0;
        int max = 0;

        min = Integer.parseInt(sc.next());
        max = Integer.parseInt(sc.next());

        for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        }

        int counter = 0;
        for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        }
        System.out.println(counter);
    } main {
        Scanner sc = new Scanner(System.in);
        int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
        int min = 0;
        int max = 0;

        min = Integer.parseInt(sc.next());
        max = Integer.parseInt(sc.next());

        for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        }

        int counter = 0;
        for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        }
        System.out.println(counter);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int cardNum = Integer.parseInt(sc.next()); cardNum Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int gateNum = Integer.parseInt(sc.next()); gateNum Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int min = 0; min 0 int max = 0; max 0 min = Integer.parseInt(sc.next()) min Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc max = Integer.parseInt(sc.next()) max Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        } int gtn = 1; int gtn = 1; gtn 1 gtn < gateNum gtn gateNum gtn++ gtn++ gtn {
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        } {
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        } int mint = Integer.parseInt(sc.next()); mint Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(min < mint) min = mint; min < mint min mint min = mint min mint int maxt = Integer.parseInt(sc.next()); maxt Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(max > maxt) max = maxt; max > maxt max maxt max = maxt max maxt int counter = 0; counter 0 for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        } int i = 1; int i = 1; i 1 i <= cardNum i cardNum i++ i++ i {
            if(i >= min && i <= max) counter++;
        } {
            if(i >= min && i <= max) counter++;
        } if(i >= min && i <= max) counter++; i >= min && i <= max i >= min i min i <= max i max counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
        int min = 0;
        int max = 0;

        min = Integer.parseInt(sc.next());
        max = Integer.parseInt(sc.next());

        for(int gtn = 1; gtn < gateNum; gtn++){
            int mint = Integer.parseInt(sc.next());
            if(min < mint) min = mint;
            int maxt = Integer.parseInt(sc.next());
            if(max > maxt) max = maxt;
        }

        int counter = 0;
        for(int i = 1; i <= cardNum; i++) {
            if(i >= min && i <= max) counter++;
        }
        System.out.println(counter);
    }
}