import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
}

class card{
    int l;
    int r;
    
    public card(int l, int r){
        this.l = l;
        this.r = r;
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.math.*; math.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc ArrayList<card> cards = new ArrayList<>(); cards new ArrayList<>() for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc card c = new card(l,r); c new card(l,r) cards.add(c) cards.add cards c int left = 0; left 0 int right = Integer.MAX_VALUE; right Integer.MAX_VALUE Integer Integer.MAX_VALUE for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        } card c cards {
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        } {
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        } left = Math.max(left,c.l) left Math.max(left,c.l) Math.max Math left c.l c c.l right = Math.min(right,c.r) right Math.min(right,c.r) Math.min Math right c.r c c.r if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        } right-left < 0 right-left right left 0 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(right-left+1);
        } 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 class card{
    int l;
    int r;
    
    public card(int l, int r){
        this.l = l;
        this.r = r;
    }
} card int l; l int r; r public card(int l, int r){
        this.l = l;
        this.r = r;
    } card {
        this.l = l;
        this.r = r;
    } this.l = l this.l this this.l l this.r = r this.r this this.r r int l l int r r public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
} Main
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<card> cards = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            card c = new card(l,r);
            cards.add(c);
        }
        //cards.sort((a,b) -> a.l-b.l);
        int left = 0;
        int right = Integer.MAX_VALUE;
        for(card c : cards){
            left = Math.max(left,c.l);
            right = Math.min(right,c.r);
        }
        if(right-left < 0){
            System.out.println(0);
        }else{
            System.out.println(right-left+1);
        }
    }
}

class card{
    int l;
    int r;
    
    public card(int l, int r){
        this.l = l;
        this.r = r;
    }
}