import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  } main {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int M = scanner.nextInt(); M scanner.nextInt() scanner.nextInt scanner int left = 0 left 0 right = N; right N for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    } {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    } int l = scanner.nextInt(); l scanner.nextInt() scanner.nextInt scanner int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner if (l > right || r < left) {
        System.out.println(0);
        return;
      } l > right || r < left l > right l right r < left r left {
        System.out.println(0);
        return;
      } System.out.println(0) System.out.println System.out System System.out 0 return; if (l > left) left = l; l > left l left left = l left l if (r < right) right = r; r < right r right right = r right r System.out.println(right - left + 1) System.out.println System.out System System.out right - left + 1 right - left right left 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int left = 0, right = N;
    for (int i = 0; i < M; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      if (l > right || r < left) {
        System.out.println(0);
        return;
      }
      if (l > left) left = l;
      if (r < right) right = r;
    }
    System.out.println(right - left + 1);
  }
}
