import java.util.Scanner;

public class Main {

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

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

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

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	} main {
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	} 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 cardNums[] = new int[2 * M + 1]; cardNums new int[2 * M + 1] 2 * M + 1 2 * M 2 M 1 for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		} int i = 1; int i = 1; i 1 i <= M i M i++ i++ i {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		} {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		} cardNums[i] = in.nextInt() cardNums[i] cardNums i in.nextInt() in.nextInt in cardNums[i + M] = in.nextInt() cardNums[i + M] cardNums i + M i M in.nextInt() in.nextInt in int limR = N; limR N int limL = 1; limL 1 for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		} int i = 1; int i = 1; i 1 i <= M i M i++ i++ i {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		} {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		} if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			} limL < cardNums[i] limL cardNums[i] cardNums i {
				limL = cardNums[i];
			} limL = cardNums[i] limL cardNums[i] cardNums i for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		} int i = M + 1; int i = M + 1; i M + 1 M 1 i <= 2*M i 2*M 2 M i++ i++ i {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		} {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		} if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			} limR > cardNums[i] limR cardNums[i] cardNums i {
				limR = cardNums[i];
			} limR = cardNums[i] limR cardNums[i] cardNums i if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		} limL > limR limL limR {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(limR - limL + 1);
		} System.out.println(limR - limL + 1) System.out.println System.out System System.out limR - limL + 1 limR - limL limR limL 1 in.close() in.close in String[] args args public class Main {

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

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	}
} public class Main {

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

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	}
} Main
import java.util.Scanner;

public class Main {

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

		int N = in.nextInt();
		int M = in.nextInt();
		int cardNums[] = new int[2 * M + 1];

		for ( int i = 1; i <= M; i++ ) {
			cardNums[i] = in.nextInt();
			cardNums[i + M] = in.nextInt();
		}

		int limR = N;
		int limL = 1;
		
		for ( int i = 1; i <= M; i++ ) {
			if ( limL < cardNums[i] ) {
				limL = cardNums[i];
			}
		}
		for ( int i = M + 1; i <= 2*M; i++ ) {
			if ( limR > cardNums[i] ) {
				limR = cardNums[i];
			}
		}
		
		if ( limL > limR ) {
			System.out.println(0);
		} else {
			System.out.println(limR - limL + 1);
		}
		
		in.close();
	}
}