import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


public class Main{
  public static void main(String[] args){
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io public class Main{
  public static void main(String[] args){
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  }
} Main public static void main(String[] args){
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  } main {
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  } try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    } catch(IOException e){
      System.out.println(e);
    } IOException e {
      System.out.println(e);
    } System.out.println(e) System.out.println System.out System System.out e {
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    } BufferedReader re = new BufferedReader(new InputStreamReader(System.in)); re new BufferedReader(new InputStreamReader(System.in)) String as = re.readLine(); as re.readLine() re.readLine re String aa[] = as.split(" "); aa as.split(" ") as.split as " " String aaa = aa[0]; aaa aa[0] aa 0 String bbb = aa[1]; bbb aa[1] aa 1 int a = Integer.parseInt(aaa); a Integer.parseInt(aaa) Integer.parseInt Integer aaa int b = Integer.parseInt(bbb); b Integer.parseInt(bbb) Integer.parseInt Integer bbb int[][] c = new int[b][2]; c new int[b][2] b 2 int ans = 0; ans 0 int max = 0; max 0 int min = 0; min 0 for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    } int i = 0; int i = 0; i 0 i < b i b i++ i++ i {
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    } {
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    } String al = re.readLine(); al re.readLine() re.readLine re String bb[] = al.split(" "); bb al.split(" ") al.split al " " String ccc = bb[0]; ccc bb[0] bb 0 String ddd = bb[1]; ddd bb[1] bb 1 c[i][0] = Integer.parseInt(ccc) c[i][0] c[i] c i 0 Integer.parseInt(ccc) Integer.parseInt Integer ccc c[i][1] = Integer.parseInt(ddd) c[i][1] c[i] c i 1 Integer.parseInt(ddd) Integer.parseInt Integer ddd for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      } int x = 0; int x = 0; x 0 x < b x b x++ x++ x {
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      } {
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      } if(c[x][0] > max) max = c[x][0]; c[x][0] > max c[x][0] c[x] c x 0 max max = c[x][0] max c[x][0] c[x] c x 0 if(c[x][1] < min || x == 0) min = c[x][1]; c[x][1] < min || x == 0 c[x][1] < min c[x][1] c[x] c x 1 min x == 0 x 0 min = c[x][1] min c[x][1] c[x] c x 1 for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    } int x = 1; int x = 1; x 1 x <= a x a x++ x++ x {
      if(x >= max && x <= min) ans++;
    } {
      if(x >= max && x <= min) ans++;
    } if(x >= max && x <= min) ans++; x >= max && x <= min x >= max x max x <= min x min ans++ ans 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{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  }
} public class Main{
  public static void main(String[] args){
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


public class Main{
  public static void main(String[] args){
    try{
    BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
    String as = re.readLine();
    String aa[] = as.split(" ");
    String aaa = aa[0];
    String bbb = aa[1];  
    int a = Integer.parseInt(aaa);
    int b = Integer.parseInt(bbb);
    int[][] c = new int[b][2];
    int ans = 0;
    int max = 0;
    int min = 0;  
    for(int i = 0;i < b;i++){
      String al = re.readLine();
      String bb[] = al.split(" ");
      String ccc = bb[0];
      String ddd = bb[1];  
      c[i][0] = Integer.parseInt(ccc);
      c[i][1] = Integer.parseInt(ddd);      
    }
      for(int x = 0;x < b;x++){
        if(c[x][0] > max) max = c[x][0];
        if(c[x][1] < min || x == 0) min = c[x][1];
      }  
    for(int x = 1;x <= a;x++){
      if(x >= max && x <= min) ans++;
    }
    System.out.println(ans);
    }catch(IOException e){
      System.out.println(e);
    }
  }
}