import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
} Main public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int l = 1; l 1 int r = n; r n for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		} int i = 1; int i = 1; i 1 i <= m i m i++ i++ i {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		} {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		} int tl = Integer.parseInt(sc.next()); tl Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int tr = Integer.parseInt(sc.next()); tr Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if (l < tl) l = tl; l < tl l tl l = tl l tl if (tr < r) r = tr; tr < r tr r r = tr r tr if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		} r < l r l {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(r - l + 1);
		} System.out.println(r - l + 1) System.out.println System.out System System.out r - l + 1 r - l r l 1 sc.close() sc.close sc String[] args args public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
} public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		int l = 1;
		int r = n;

		for (int i = 1; i <= m; i++) {
			int tl = Integer.parseInt(sc.next());
			int tr = Integer.parseInt(sc.next());

			if (l < tl) l = tl;
			if (tr < r) r = tr;
		}

		if (r < l) {
			System.out.println(0);
		} else {
			System.out.println(r - l + 1);
		}

		sc.close();
	}
}