import java.util.Scanner;

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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        }
    }
} import java.util.Scanner; Scanner 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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        }
    }
} 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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }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 min = n+1; min n+1 n 1 int max = 0; max 0 int l l r; r for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        } {
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        } l = Integer.parseInt(sc.next()) l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc min = Math.min(r,min) min Math.min(r,min) Math.min Math r min max = Math.max(l,max) max Math.max(l,max) Math.max Math l max if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        } min-max>=0 min-max min max 0 {
            System.out.println(min-max+1);
        } System.out.println(min-max+1) System.out.println System.out System System.out min-max+1 min-max min max 1 {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 String[] args args 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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        }
    }
} 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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        }
    }
} Main
import java.util.Scanner;

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 min = n+1;
        int max = 0;
        int l,r;
        for(int i=0;i<m;i++){
            l = Integer.parseInt(sc.next());
            r = Integer.parseInt(sc.next());
            min = Math.min(r,min);
            max = Math.max(l,max);
        }
        if(min-max>=0){
            System.out.println(min-max+1);
        }else{
            System.out.println(0);
        }
    }
}