
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  }
} Main public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  } main {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  } try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    } {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int l = 0 l 0 r = N; r N for (int i = 0; i < M; i++) {
        l = Math.max(l, sc.nextInt());
        r = Math.min(r, sc.nextInt());
      } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
        l = Math.max(l, sc.nextInt());
        r = Math.min(r, sc.nextInt());
      } {
        l = Math.max(l, sc.nextInt());
        r = Math.min(r, sc.nextInt());
      } l = Math.max(l, sc.nextInt()) l Math.max(l, sc.nextInt()) Math.max Math l sc.nextInt() sc.nextInt sc r = Math.min(r, sc.nextInt()) r Math.min(r, sc.nextInt()) Math.min Math r sc.nextInt() sc.nextInt sc int ans = r >= l ? (r - l + 1) : 0 ; ans r >= l ? (r - l + 1) : 0 r >= l r l (r - l + 1) r - l r l 1 0 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  }
} public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

      int ans = r >= l ? (r - l + 1) : 0 ;
      System.out.println(ans);
    }
  }
} Main

import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int N = sc.nextInt();// card
      int M = sc.nextInt();// gate
      int l = 0, r = N;

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

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