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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    }
} 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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    }
} 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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    } 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 mi = N; mi N int ma = 1; ma 1 for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        } {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        } int l = Integer.parseInt(sc.next()); l Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(ma < l){
                ma = l;
            } ma < l ma l {
                ma = l;
            } ma = l ma l if(mi > r){
                mi = r;
            } mi > r mi r {
                mi = r;
            } mi = r mi r if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        } ma > mi ma mi {
            System.out.println(0);
        } System.out.println(0) System.out.println System.out System System.out 0 {
            System.out.println(mi-ma+1);
        } System.out.println(mi-ma+1) System.out.println System.out System System.out mi-ma+1 mi-ma mi ma 1 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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    }
} 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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    }
} 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 mi = N;
        int ma = 1;
        for(int i = 0;i < M;i++){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(ma < l){
                ma = l;
            }
            if(mi > r){
                mi = r;
            }
        }
        if(ma > mi){
            System.out.println(0);
        }else{
            System.out.println(mi-ma+1);
        }
    }
}