

import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	}
} Main public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	} main {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int m=scan.nextInt(); m scan.nextInt() scan.nextInt scan int l=0; l 0 int r=n; r n for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		} {
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		} int a=scan.nextInt(); a scan.nextInt() scan.nextInt scan int b=scan.nextInt(); b scan.nextInt() scan.nextInt scan if(a>l)
			{
				l=a;
			} a>l a l {
				l=a;
			} l=a l a if(b<r) {
				r=b;
			} b<r b r {
				r=b;
			} r=b r b if(b<l || a>r) {
				System.out.println(0);
				return;
			} b<l || a>r b<l b l a>r a r {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; System.out.println(r-l+1) System.out.println System.out System System.out r-l+1 r-l r l 1 String args[] args public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	}
} public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	}
} Main


import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int l=0;
		int r=n;
		for(int i=0;i<m;i++)
		{
			int a=scan.nextInt();
			int b=scan.nextInt();
			if(a>l)
			{
				l=a;
			}
			if(b<r) {
				r=b;
			}
			if(b<l || a>r) {
				System.out.println(0);
				return;
			}
		}
		System.out.println(r-l+1);
	}
}
