import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) String[] str = in.readLine().split(" "); str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int m = Integer.parseInt(str[1]); m Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m int l_max = 0; l_max 0 int r_min = 100000; r_min 100000 for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    } {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    } str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " l[i] = Integer.parseInt(str[0]) l[i] l i Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 l_max = Math.max(l[i],l_max) l_max Math.max(l[i],l_max) Math.max Math l[i] l i l_max r[i] = Integer.parseInt(str[1]) r[i] r i Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 r_min = Math.min(r[i],r_min) r_min Math.min(r[i],r_min) Math.min Math r[i] r i r_min System.out.println(r_min-l_max+1>0?r_min-l_max+1:0) System.out.println System.out System System.out r_min-l_max+1>0?r_min-l_max+1:0 r_min-l_max+1>0 r_min-l_max+1 r_min-l_max r_min l_max 1 0 r_min-l_max+1 r_min-l_max r_min l_max 1 0 String[] args args public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
} public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] l = new int[m];
    int[] r = new int[m];
    int l_max = 0;
    int r_min = 100000;
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      l[i] = Integer.parseInt(str[0]);
      l_max = Math.max(l[i],l_max);
      r[i] = Integer.parseInt(str[1]);
      r_min = Math.min(r[i],r_min);
    }
    System.out.println(r_min-l_max+1>0?r_min-l_max+1:0);
  }
}