import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  }
} Main public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  } main {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int N = scn.nextInt(); N scn.nextInt() scn.nextInt scn int M = scn.nextInt(); M scn.nextInt() scn.nextInt scn int Lmax = scn.nextInt(); Lmax scn.nextInt() scn.nextInt scn int Rmin = scn.nextInt(); Rmin scn.nextInt() scn.nextInt scn for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    } int i = 1; int i = 1; i 1 i < M i M i++ i++ i {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    } {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    } int L = scn.nextInt(); L scn.nextInt() scn.nextInt scn if (L > Lmax) {
        Lmax = L;
      } L > Lmax L Lmax {
        Lmax = L;
      } Lmax = L Lmax L int R = scn.nextInt(); R scn.nextInt() scn.nextInt scn if (R < Rmin) {
        Rmin = R;
      } R < Rmin R Rmin {
        Rmin = R;
      } Rmin = R Rmin R if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    } Rmin - Lmax < 0 Rmin - Lmax Rmin Lmax 0 {
      System.out.println(0);
    } System.out.println(0) System.out.println System.out System System.out 0 {
      System.out.println(Rmin - Lmax + 1);
    } System.out.println(Rmin - Lmax + 1) System.out.println System.out System System.out Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  }
} public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int N = scn.nextInt();
    int M = scn.nextInt();

    int Lmax = scn.nextInt();
    int Rmin = scn.nextInt();
    for (int i = 1; i < M; i++) {
      int L = scn.nextInt();
      if (L > Lmax) {
        Lmax = L;
      }
      int R = scn.nextInt();
      if (R < Rmin) {
        Rmin = R;
      }
    }

    if (Rmin - Lmax < 0) {
      System.out.println(0);
    } else {
      System.out.println(Rmin - Lmax + 1);
    }

  }
}