import java.io.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
} import java.io.*; io.* java public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
} Main public static void main(String[] args) {
    new Main().run();
  } main {
    new Main().run();
  } new Main().run() new Main().run new Main() String[] args args private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  } run {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  } try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    } catch(IOException e) {
      System.err.println(e);
    } IOException e {
      System.err.println(e);
    } System.err.println(e) System.err.println System.err System System.err e {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) BufferedReader in = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(System.out) PrintWriter out = new PrintWriter(System.out) new PrintWriter(System.out) String[] lines = in.readLine().split(" "); lines in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int n = Integer.parseInt(lines[0]); n Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 int m = Integer.parseInt(lines[1]); m Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 1 int l = 1; l 1 int r = n; r n int lc lc rc; rc for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        } {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        } lines = in.readLine().split(" ") lines in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " lc = Integer.parseInt(lines[0]) lc Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 rc = Integer.parseInt(lines[1]) rc Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 1 if(l < lc) l = lc; l < lc l lc l = lc l lc if(rc < r) r = rc; rc < r rc r r = rc r rc int ans = Math.max(1 + r - l, 0); ans Math.max(1 + r - l, 0) Math.max Math 1 + r - l 1 + r 1 r l 0 out.println(ans) out.println out ans out.flush() out.flush out public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
} public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
} Main
import java.io.*;

public class Main {
  public static void main(String[] args) {
    new Main().run();
  }

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

        String[] lines = in.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);

        int l = 1;
        int r = n;
        int lc, rc;
        for (int i = 0; i < m; i++) {
          lines = in.readLine().split(" ");
          lc = Integer.parseInt(lines[0]);
          rc = Integer.parseInt(lines[1]);
          if(l < lc) l = lc;
          if(rc < r) r = rc;
        }

        int ans = Math.max(1 + r - l, 0);
        out.println(ans);
        out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}