import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
} import java.util.Scanner; Scanner java.util public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
} Main public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	} main {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int m = s.nextInt(); m s.nextInt() s.nextInt s int lMax = 1; lMax 1 int rMin = n; rMin n for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        } {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        } int l = s.nextInt(); l s.nextInt() s.nextInt s int r = s.nextInt(); r s.nextInt() s.nextInt s lMax = (lMax < l ? l : lMax) lMax (lMax < l ? l : lMax) lMax < l lMax l l lMax rMin = (rMin > r ? r : rMin) rMin (rMin > r ? r : rMin) rMin > r rMin r r rMin int res = rMin - lMax + 1; res rMin - lMax + 1 rMin - lMax rMin lMax 1 System.out.println((res < 0)? 0 : res) System.out.println System.out System System.out (res < 0)? 0 : res (res < 0) res 0 0 res String[] args args public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
} public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
} Main
import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
}