
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

} import java.io.FileNotFoundException; FileNotFoundException java.io import java.io.FileReader; FileReader java.io import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

} Main public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  } main {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  } Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int n = cin.nextInt(); n cin.nextInt() cin.nextInt cin int m = cin.nextInt(); m cin.nextInt() cin.nextInt cin int l=0; l 0 int r=0; r 0 int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    } {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    } l = cin.nextInt() l cin.nextInt() cin.nextInt cin r = cin.nextInt() r cin.nextInt() cin.nextInt cin max = Math.max(l, max) max Math.max(l, max) Math.max Math l max min = Math.min(r, min) min Math.min(r, min) Math.min Math r min min = Math.min(min,n) min Math.min(min,n) Math.min Math min n System.out.println(Math.max(min-max+1,0)) System.out.println System.out System System.out Math.max(min-max+1,0) Math.max Math min-max+1 min-max min max 1 0 String[] args args public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

} public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

} Main

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int m = cin.nextInt();
    int l=0;
    int r=0;
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < m; i++) {
      l = cin.nextInt();
      r = cin.nextInt();
      max = Math.max(l, max);
      min = Math.min(r, min);
    }
    min = Math.min(min,n);
    System.out.println(Math.max(min-max+1,0));

  }

}
