import java.util.*;

public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
} import java.util.*; util.* java public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int lmax = -1; lmax -1 1 int rmin = Integer.MAX_VALUE; rmin Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        } {
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        } lmax = Math.max(lmax, sc.nextInt()) lmax Math.max(lmax, sc.nextInt()) Math.max Math lmax sc.nextInt() sc.nextInt sc rmin = Math.min(rmin, sc.nextInt()) rmin Math.min(rmin, sc.nextInt()) Math.min Math rmin sc.nextInt() sc.nextInt sc if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        } lmax > rmin lmax rmin {
            System.out.println("0");
        } System.out.println("0") System.out.println System.out System System.out "0" {
            System.out.println(rmin-lmax+1);
        } System.out.println(rmin-lmax+1) System.out.println System.out System System.out rmin-lmax+1 rmin-lmax rmin lmax 1 String args[] args public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
} public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
} Main
import java.util.*;

public class Main {


    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax = -1;
        int rmin = Integer.MAX_VALUE;

        for(int i = 0;i < m;i++){
            lmax = Math.max(lmax, sc.nextInt());
            rmin = Math.min(rmin, sc.nextInt());
        }

        if(lmax > rmin) {
            System.out.println("0");
        } else {
            System.out.println(rmin-lmax+1);
        }
    }
}