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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+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[] a = {0,100001}; a {0,100001} 0 100001 boolean flag = true; flag true while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        } m>0 m 0 {
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        } 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(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            } r < a[0] || a[1] < l r < a[0] r a[0] a 0 a[1] < l a[1] a 1 l {
                System.out.println(0);
                flag = false;
                break;
            } System.out.println(0) System.out.println System.out System System.out 0 flag = false flag false break; if(a[0] < l){
                a[0] = l;
            } a[0] < l a[0] a 0 l {
                a[0] = l;
            } a[0] = l a[0] a 0 l if(r < a[1]){
                a[1] = r;
            } r < a[1] r a[1] a 1 {
                a[1] = r;
            } a[1] = r a[1] a 1 r m-- m sc.close() sc.close sc if(flag){
            System.out.println(a[1]-a[0]+1);
        } flag {
            System.out.println(a[1]-a[0]+1);
        } System.out.println(a[1]-a[0]+1) System.out.println System.out System System.out a[1]-a[0]+1 a[1]-a[0] a[1] a 1 a[0] a 0 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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+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[] a = {0,100001};
        boolean flag = true;
        while(m>0){
            int l = Integer.parseInt(sc.next());
            int r = Integer.parseInt(sc.next());
            if(r < a[0] || a[1] < l){
                System.out.println(0);
                flag = false;
                break;
            }
            if(a[0] < l){
                a[0] = l;
            }
            if(r < a[1]){
                a[1] = r;
            }
            m--;
        }
        sc.close();
        if(flag){
            System.out.println(a[1]-a[0]+1);
        }
    }
}
