import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

} import java.util.*; util.* java public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

} Main public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  } main {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  } int rep = 1; rep 1 if( args.length > 0 ) { rep = Integer.parseInt(args[0]); } args.length > 0 args.length args args.length 0 { rep = Integer.parseInt(args[0]); } rep = Integer.parseInt(args[0]) rep Integer.parseInt(args[0]) Integer.parseInt Integer args[0] args 0 (new Main()).__solve(rep) (new Main()).__solve (new Main()) rep String args[] args void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  } __solve {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  } try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    } {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    } Scanner cin = new Scanner(System.in) Scanner cin = new Scanner(System.in) new Scanner(System.in) for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      } int i = 0; int i = 0; i 0 i < rep i rep ++i ++i i {
        __solve(cin);
      } {
        __solve(cin);
      } __solve(cin) __solve cin int rep rep void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  } __solve {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  } int N = cin.nextInt(); N cin.nextInt() cin.nextInt cin int K = cin.nextInt(); K cin.nextInt() cin.nextInt cin int min = 1; min 1 int max = N; max N for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  } int i = 0; int i = 0; i 0 i < K i K ++i ++i i {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  } {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  } int L = cin.nextInt(); L cin.nextInt() cin.nextInt cin int R = cin.nextInt(); R cin.nextInt() cin.nextInt cin min = Math.max(min, L) min Math.max(min, L) Math.max Math min L max = Math.min(max, R) max Math.min(max, R) Math.min Math max R System.out.println(Math.max(0, max - min + 1)) System.out.println System.out System System.out Math.max(0, max - min + 1) Math.max Math 0 max - min + 1 max - min max min 1 Scanner cin cin public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

} public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

} Main
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {
	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int min = 1;
	  int max = N;
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt();
		  int R = cin.nextInt();
		  min = Math.max(min, L);
		  max = Math.min(max, R);
	  }
	  System.out.println(Math.max(0, max - min + 1));
  }

}
