import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

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

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

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

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    } main {
      Scanner sc = new Scanner(System.in);

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] L = new int[m]; L new int[m] m int[] R = new int[m]; R new int[m] m for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      } int i=0; int i=0; i 0 i<m i m i++ i++ i {
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      } {
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      } L[i] = Integer.parseInt(sc.next()) L[i] L i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc R[i] = Integer.parseInt(sc.next()) R[i] R i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int max = cmax(L,m); max cmax(L,m) cmax L m int min = cmin(R,m); min cmin(R,m) cmin R m int ans = min - max + 1; ans min - max + 1 min - max min max 1 if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      } ans>=0 ans 0 {
        System.out.println(ans);
      } System.out.println(ans) System.out.println System.out System System.out ans {
        System.out.println("0");
      } System.out.println("0") System.out.println System.out System System.out "0" String[] args args public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    } cmax {
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    } int max1=aa[0]; max1 aa[0] aa 0 for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      } int j=1; int j=1; j 1 j<nn j nn j++ j++ j {
        if(aa[j]>max1){
          max1=aa[j];
        }
      } {
        if(aa[j]>max1){
          max1=aa[j];
        }
      } if(aa[j]>max1){
          max1=aa[j];
        } aa[j]>max1 aa[j] aa j max1 {
          max1=aa[j];
        } max1=aa[j] max1 aa[j] aa j return max1; max1 int[] aa aa int nn nn public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    } cmin {
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    } int min1=bb[0]; min1 bb[0] bb 0 for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      } int j=1; int j=1; j 1 j<nn j nn j++ j++ j {
        if(bb[j]<min1){
          min1=bb[j];
        }
      } {
        if(bb[j]<min1){
          min1=bb[j];
        }
      } if(bb[j]<min1){
          min1=bb[j];
        } bb[j]<min1 bb[j] bb j min1 {
          min1=bb[j];
        } min1=bb[j] min1 bb[j] bb j return min1; min1 int[] bb bb int nn nn public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

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

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

} Main
import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int m = Integer.parseInt(sc.next());

      int[] L = new int[m];
      int[] R = new int[m];


      for(int i=0;i<m;i++){
        L[i] = Integer.parseInt(sc.next());
        R[i] = Integer.parseInt(sc.next());
      }

      int max = cmax(L,m);
      int min = cmin(R,m);

      int ans = min - max + 1;

      if(ans>=0){
        System.out.println(ans);
      }
      else{
        System.out.println("0");
      }

    }

    public static int cmax(int[] aa,int nn){
      int max1=aa[0];
      for(int j=1;j<nn;j++){
        if(aa[j]>max1){
          max1=aa[j];
        }
      }
      return max1;
    }
    public static int cmin(int[] bb,int nn){
      int min1=bb[0];
      for(int j=1;j<nn;j++){
        if(bb[j]<min1){
          min1=bb[j];
        }
      }
      return min1;
    }

}
