import java.util.*;

public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  } main {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n m; m n = sc.nextInt() n sc.nextInt() sc.nextInt sc m = sc.nextInt() m sc.nextInt() sc.nextInt sc int x x y y l l r; r l = 0 l 0 r = (int)1E5 + 10 r (int)1E5 + 10 (int)1E5 10 for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    } {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    } x = sc.nextInt() x sc.nextInt() sc.nextInt sc y = sc.nextInt() y sc.nextInt() sc.nextInt sc l = Math.max(x, l) l Math.max(x, l) Math.max Math x l r = Math.min(y, r) r Math.min(y, r) Math.min Math y r System.out.println(l <= r ? r - l + 1 : 0) System.out.println System.out System System.out l <= r ? r - l + 1 : 0 l <= r l r r - l + 1 r - l r l 1 0 String[] args args public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  }
} public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n, m;
    n = sc.nextInt();
    m = sc.nextInt();

    int x, y, l, r;
    l = 0;
    r = (int)1E5 + 10;

    for (int i = 0; i < m; i++) {
      x = sc.nextInt();
      y = sc.nextInt();
      l = Math.max(x, l);
      r = Math.min(y, r);
    }

    System.out.println(l <= r ? r - l + 1 : 0);
  }
}
