
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    } main {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n= in.nextInt(); n in.nextInt() in.nextInt in int m=in.nextInt(); m in.nextInt() in.nextInt in int min=1 min 1 max=n; max n boolean flag=false; flag false for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        } {
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        } int lb=in.nextInt(); lb in.nextInt() in.nextInt in int ub=in.nextInt(); ub in.nextInt() in.nextInt in if(lb>=min)
                min=lb; lb>=min lb min min=lb min lb if(ub<=max)
                max=ub; ub<=max ub max max=ub max ub if(ub<min || lb >max){
                flag=true;
            } ub<min || lb >max ub<min ub min lb >max lb max {
                flag=true;
            } flag=true flag true if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        } flag System.out.println(0) System.out.println System.out System System.out 0 {
            int ans = max - min + 1;
            System.out.println(ans);
        } int ans = max - min + 1; ans max - min + 1 max - min max min 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args

import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n= in.nextInt();
        int m=in.nextInt();
        int min=1, max=n;
        boolean flag=false;
        for(int i=0;i<m;i++){
            int lb=in.nextInt();
            int ub=in.nextInt();

            if(lb>=min)
                min=lb;
            if(ub<=max)
                max=ub;

            if(ub<min || lb >max){
                flag=true;
            }

        }
        if(flag)
            System.out.println(0);
        else {
            int ans = max - min + 1;
            System.out.println(ans);
        }
    }
}
