import java.util.Scanner;

class Main {
    public static void main (String args[]) {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main (String args[]) {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    }
} Main public static void main (String args[]) {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    } main {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    } int n n m m x x y y l l r; r Scanner in = new Scanner(System.in); in new Scanner(System.in) n = in.nextInt() n in.nextInt() in.nextInt in m = in.nextInt() m in.nextInt() in.nextInt in x = y = 0 x y = 0 y 0 while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        } m>0 m 0 {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        } l = in.nextInt() l in.nextInt() in.nextInt in r = in.nextInt() r in.nextInt() in.nextInt in if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            } x!=-1 && y!=-1 x!=-1 x -1 1 y!=-1 y -1 1 {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            } if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                } x==0 && y==0 x==0 x 0 y==0 y 0 {
                    x = l;
                    y = r;
                } x = l x l y = r y r {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                } x = Math.max(x,l) x Math.max(x,l) Math.max Math x l y = Math.min(y,r) y Math.min(y,r) Math.min Math y r if(x>y)
                        x = y = -1; x>y x y x = y = -1 x y = -1 y -1 1 m-- m int cnt = 0; cnt 0 if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1; x==-1 && y==-1 x==-1 x -1 1 y==-1 y -1 1 cnt = 0 cnt 0 cnt = y-x+1 cnt y-x+1 y-x y x 1 System.out.print(cnt) System.out.print System.out System System.out cnt String args[] args
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    }
}
