import  java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;

public class Main
{  

    
    public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } 

    
    static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    }

    static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    }


    //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    }

    static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    }

   
    static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    }

   static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   }
 
   

    

    static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    }

   


   
   
  
    public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    }


   

    static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    }

    static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } 
     

    
   
    static Scanner in = new Scanner(System.in);
    static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    }  


 

    

    //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    }

    static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    }


    

  
   
    

    
       
    

    
   
  



   

    static void printL(long a)
    {
        System.out.println(a);
    }
    static void printS(String s)
    {
        System.out.println(s);
    }

    static void printD(Double d)
    {
        System.out.println(d);
    }
  
   
   
    static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    }

    static long max(long n,long m)
    {
        return Math.max(n,m);
    }
    static long min(long n,long m)
    {
        return Math.min(n,m);
    }

    static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    }
    static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    }

    static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    }

    static String si() throws IOException
    {
        return in.next();
    }


  
   
    static int abs(int n)
    {
        return Math.abs(n);
    }

    static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }

    
}



class Pair implements Comparable<Pair>
{
    int x;
    int y;
    public Pair(int x,int y)
    {
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair o)
    {
        return this.x-o.x;
    }
} import  java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.util.*; util.* java import java.math.*; math.* java import java.io.*; io.* java import java.text.*; text.* java public class Main
{  

    
    public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } 

    
    static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    }

    static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    }


    //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    }

    static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    }

   
    static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    }

   static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   }
 
   

    

    static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    }

   


   
   
  
    public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    }


   

    static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    }

    static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } 
     

    
   
    static Scanner in = new Scanner(System.in);
    static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    }  


 

    

    //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    }

    static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    }


    

  
   
    

    
       
    

    
   
  



   

    static void printL(long a)
    {
        System.out.println(a);
    }
    static void printS(String s)
    {
        System.out.println(s);
    }

    static void printD(Double d)
    {
        System.out.println(d);
    }
  
   
   
    static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    }

    static long max(long n,long m)
    {
        return Math.max(n,m);
    }
    static long min(long n,long m)
    {
        return Math.min(n,m);
    }

    static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    }
    static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    }

    static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    }

    static String si() throws IOException
    {
        return in.next();
    }


  
   
    static int abs(int n)
    {
        return Math.abs(n);
    }

    static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }

    
} Main static Scanner in = new Scanner(System.in); in new Scanner(System.in) public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } sieve {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } boolean[] prime = new boolean[(int)n+1]; prime new boolean[(int)n+1] (int)n+1 (int)n 1 Arrays.fill(prime,true) Arrays.fill Arrays prime true prime[0] = false prime[0] prime 0 false prime[1] = false prime[1] prime 1 false long m = (long)Math.sqrt(n); m (long)Math.sqrt(n) Math.sqrt Math n for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        } int i=2; int i=2; i 2 i<=m i m i++ i++ i {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        } {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        } if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            } prime[i] prime i {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            } for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                } int k=i*i; int k=i*i; k i*i i i k<=n k n k+=i k+=i k i {
                    prime[k] = false;
                } {
                    prime[k] = false;
                } prime[k] = false prime[k] prime k false return prime; prime long n n static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    } GCD {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    } if(a==0 || b==0)
        {
            return 0;
        } a==0 || b==0 a==0 a 0 b==0 b 0 {
            return 0;
        } return 0; 0 if(a==b)
        {
            return a;
        } a==b a b {
            return a;
        } return a; a if(a>b)
        {
            return GCD(a-b,b);
        } a>b a b {
            return GCD(a-b,b);
        } return GCD(a-b,b); GCD(a-b,b) GCD a-b a b b return GCD(a,b-a); GCD(a,b-a) GCD a b-a b a long a a long b b static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    } CountCoPrimes {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    } long res = n; res n for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        } int i=2; int i=2; i 2 i*i<=n i*i i i n i++ i++ i {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        } {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        } if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            } n%i==0 n%i n i 0 {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            } while(n%i==0)
                {
                    n/=i;
                } n%i==0 n%i n i 0 {
                    n/=i;
                } n/=i n i res-=res/i res res/i res i if(n>1)
        {
            res-=res/n;
        } n>1 n 1 {
            res-=res/n;
        } res-=res/n res res/n res n return res; res long n n //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    } modularExponentiation {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    } long res = 1; res 1 while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        } n>0 n 0 {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        } if(n%2==1)
            {
                res = (res*x)%m;
            } n%2==1 n%2 n 2 1 {
                res = (res*x)%m;
            } res = (res*x)%m res (res*x)%m (res*x) res x m x =(x*x)%m x (x*x)%m (x*x) x x m n/=2 n 2 return res; res long x x long n n long m m static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    } lcm {
        return (a*b)/GCD(a,b);
    } return (a*b)/GCD(a,b); (a*b)/GCD(a,b) (a*b) a b GCD(a,b) GCD a b long a a long b b static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    } pow {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    } long res = 1; res 1 while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        } b>0 b 0 {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        } if((b&1)==1)
            {
                res *= a;
            } (b&1)==1 (b&1) b 1 1 {
                res *= a;
            } res *= a res a b >>= 1 b 1 a *=a a a return res; res long a a long b b static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   } modInverse {
    return modularExponentiation(A,M-2,M);
   } return modularExponentiation(A,M-2,M); modularExponentiation(A,M-2,M) modularExponentiation A M-2 M 2 M long A A long M M static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    } prime {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    } for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        } int i=2; int i=2; i 2 i*i<=n i*i i i n i++ i++ i {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        } {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        } if(i%2==0 ||i%3==0)
            {
                return false;
            } i%2==0 ||i%3==0 i%2==0 i%2 i 2 0 i%3==0 i%3 i 3 0 {
                return false;
            } return false; false return true; true int n n public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    } main {
     
        new Main().run();
       
    } new Main().run() new Main().run new Main() String[] args args static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    } reverse {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    } int start=0; start 0 int end = (int)n; end (int)n while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        } start!=end start end {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        } long temp = a[start]; temp a[start] a start a[start] = a[end] a[start] a start a[end] a end a[end] = temp a[end] a end temp start++ start end-- end long[] a a long n n static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } findGCD { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } long result = arr.get(0); result arr.get(0) arr.get arr 0 for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); int i = 1; int i = 1; i 1 i < n i n i++ i++ i result = GCD(arr.get(i), result); result = GCD(arr.get(i), result) result GCD(arr.get(i), result) GCD arr.get(i) arr.get arr i result return result; result ArrayList<Long> arr arr long n n static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    } run {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    } long n = nl(); n nl() nl long m = nl(); m nl() nl long l = nl(); l nl() nl long r = nl(); r nl() nl long x = l x l y = r; y r for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       } int i=1; int i=1; i 1 i<m i m i++ i++ i {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       } {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       } l = nl() l nl() nl r = nl() r nl() nl 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 printL(Math.max(0,y-x+1)) printL Math.max(0,y-x+1) Math.max Math 0 y-x+1 y-x y x 1 //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    } xor {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    } if(n%4==0)
        {
            return n;
        } n%4==0 n%4 n 4 0 {
            return n;
        } return n; n if(n%4==1)
        {
            return  1;
        } n%4==1 n%4 n 4 1 {
            return  1;
        } return  1; 1 if(n%4==2)
        {
            return n+1;
        } n%4==2 n%4 n 4 2 {
            return n+1;
        } return n+1; n+1 n 1 return 0; 0 long n n static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    } xor {
        return xor(b)^xor(a-1);
    } return xor(b)^xor(a-1); xor(b)^xor(a-1) xor(b) xor b xor(a-1) xor a-1 a 1 long a a long b b static void printL(long a)
    {
        System.out.println(a);
    } printL {
        System.out.println(a);
    } System.out.println(a) System.out.println System.out System System.out a long a a static void printS(String s)
    {
        System.out.println(s);
    } printS {
        System.out.println(s);
    } System.out.println(s) System.out.println System.out System System.out s String s s static void printD(Double d)
    {
        System.out.println(d);
    } printD {
        System.out.println(d);
    } System.out.println(d) System.out.println System.out System System.out d Double d d static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    } swap {
        char t = c;
        c = p;
        p = t;
    } char t = c; t c c = p c p p = t p t char c c char p p static long max(long n,long m)
    {
        return Math.max(n,m);
    } max {
        return Math.max(n,m);
    } return Math.max(n,m); Math.max(n,m) Math.max Math n m long n n long m m static long min(long n,long m)
    {
        return Math.min(n,m);
    } min {
        return Math.min(n,m);
    } return Math.min(n,m); Math.min(n,m) Math.min Math n m long n n long m m static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    } nd {
        return Double.parseDouble(in.next());
    } return Double.parseDouble(in.next()); Double.parseDouble(in.next()) Double.parseDouble Double in.next() in.next in static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    } ni {
        return Integer.parseInt(in.next());
    } return Integer.parseInt(in.next()); Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    } nl {
        return Long.parseLong(in.next());
    } return Long.parseLong(in.next()); Long.parseLong(in.next()) Long.parseLong Long in.next() in.next in static String si() throws IOException
    {
        return in.next();
    } si {
        return in.next();
    } return in.next(); in.next() in.next in static int abs(int n)
    {
        return Math.abs(n);
    } abs {
        return Math.abs(n);
    } return Math.abs(n); Math.abs(n) Math.abs Math n int n n static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    } Scanner StringTokenizer st; st BufferedReader br; br public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));} Scanner {  br = new BufferedReader(new InputStreamReader(s));} br = new BufferedReader(new InputStreamReader(s)) br new BufferedReader(new InputStreamReader(s)) InputStream s s public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
                st = new StringTokenizer(br.readLine());
            } st = new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() throws IOException {return Integer.parseInt(next());} nextInt {return Integer.parseInt(next());} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public long nextLong() throws IOException {return Long.parseLong(next());} nextLong {return Long.parseLong(next());} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public String nextLine() throws IOException {return br.readLine();} nextLine {return br.readLine();} return br.readLine(); br.readLine() br.readLine br public boolean ready() throws IOException {return br.ready();} ready {return br.ready();} return br.ready(); br.ready() br.ready br class Pair implements Comparable<Pair>
{
    int x;
    int y;
    public Pair(int x,int y)
    {
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair o)
    {
        return this.x-o.x;
    }
} Pair int x; x int y; y public Pair(int x,int y)
    {
        this.x = x;
        this.y = y;
    } Pair {
        this.x = x;
        this.y = y;
    } this.x = x this.x this this.x x this.y = y this.y this this.y y int x x int y y public int compareTo(Pair o)
    {
        return this.x-o.x;
    } compareTo {
        return this.x-o.x;
    } return this.x-o.x; this.x-o.x this.x this this.x o.x o o.x Pair o o Comparable public class Main
{  

    
    public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } 

    
    static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    }

    static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    }


    //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    }

    static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    }

   
    static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    }

   static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   }
 
   

    

    static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    }

   


   
   
  
    public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    }


   

    static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    }

    static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } 
     

    
   
    static Scanner in = new Scanner(System.in);
    static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    }  


 

    

    //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    }

    static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    }


    

  
   
    

    
       
    

    
   
  



   

    static void printL(long a)
    {
        System.out.println(a);
    }
    static void printS(String s)
    {
        System.out.println(s);
    }

    static void printD(Double d)
    {
        System.out.println(d);
    }
  
   
   
    static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    }

    static long max(long n,long m)
    {
        return Math.max(n,m);
    }
    static long min(long n,long m)
    {
        return Math.min(n,m);
    }

    static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    }
    static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    }

    static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    }

    static String si() throws IOException
    {
        return in.next();
    }


  
   
    static int abs(int n)
    {
        return Math.abs(n);
    }

    static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }

    
} public class Main
{  

    
    public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } 

    
    static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    }

    static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    }


    //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    }

    static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    }

   
    static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    }

   static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   }
 
   

    

    static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    }

   


   
   
  
    public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    }


   

    static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    }

    static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } 
     

    
   
    static Scanner in = new Scanner(System.in);
    static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    }  


 

    

    //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    }

    static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    }


    

  
   
    

    
       
    

    
   
  



   

    static void printL(long a)
    {
        System.out.println(a);
    }
    static void printS(String s)
    {
        System.out.println(s);
    }

    static void printD(Double d)
    {
        System.out.println(d);
    }
  
   
   
    static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    }

    static long max(long n,long m)
    {
        return Math.max(n,m);
    }
    static long min(long n,long m)
    {
        return Math.min(n,m);
    }

    static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    }
    static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    }

    static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    }

    static String si() throws IOException
    {
        return in.next();
    }


  
   
    static int abs(int n)
    {
        return Math.abs(n);
    }

    static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }

    
} Main
import  java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;

public class Main
{  

    
    public static boolean[] sieve(long n)
    {
        boolean[] prime = new boolean[(int)n+1];
        Arrays.fill(prime,true);
        prime[0] = false;
        prime[1] = false;
        long m = (long)Math.sqrt(n);
        for(int i=2;i<=m;i++)
        {
            if(prime[i])
            {
                for(int k=i*i;k<=n;k+=i)
                {
                    prime[k] = false;
                }
            }
        }
        return prime;
    } 

    
    static long GCD(long a,long b)
    {
        if(a==0 || b==0)
        {
            return 0;
        }
        if(a==b)
        {
            return a;
        }
        if(a>b)
        {
            return GCD(a-b,b);
        }
        return GCD(a,b-a);
    }

    static long CountCoPrimes(long n)
    {
        long res = n;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    n/=i;
                }
                res-=res/i;
            }
        }
        if(n>1)
        {
            res-=res/n;
        }
        return res;
    }


    //fastest way to find x**n
    static long modularExponentiation(long x,long n,long m)
    {
        long res = 1;
        while(n>0)
        {
            if(n%2==1)
            {
                res = (res*x)%m;
            }
            x =(x*x)%m;
            n/=2;
        }
        return res;
    }

    static long lcm(long a,long b)
    {
        return (a*b)/GCD(a,b);
    }

   
    static long pow(long a,long b)
    {
        long res = 1;
        while(b>0)
        {
            if((b&1)==1)
            {
                res *= a;
            }

            b >>= 1;
            a *=a;
        }
        return res;
    }

   static long modInverse(long A,long M)
   {
    return modularExponentiation(A,M-2,M);
   }
 
   

    

    static boolean prime(int n)
    {
        for(int i=2;i*i<=n;i++)
        {
            if(i%2==0 ||i%3==0)
            {
                return false;
            }
        }
        return true;
    }

   


   
   
  
    public static void main(String[] args) throws IOException
    {
     
        new Main().run();
       
    }


   

    static void reverse(long[] a,long n)
    {
        int start=0;
        int end = (int)n;
        while(start!=end)
        {
            long temp = a[start];
            a[start] = a[end];
            a[end] = temp;
            start++;
            end--;
        }
    }

    static long findGCD(ArrayList<Long> arr, long n) 
    { 
        long result = arr.get(0); 
        for (int i = 1; i < n; i++) 
            result = GCD(arr.get(i), result); 
  
        return result; 
    } 
     

    
   
    static Scanner in = new Scanner(System.in);
    static void run() throws IOException
    {
       long n = nl();
       long m = nl();
       long l = nl();
       long r = nl();
       long x = l,y = r;
       for(int i=1;i<m;i++)
       {
            l = nl();
            r = nl();
            x = Math.max(x,l);
            y = Math.min(y,r);
       }
       // System.out.println(y+" "+x);

       printL(Math.max(0,y-x+1));

    }  


 

    

    //xor range query
    static long xor(long n)
    {

        if(n%4==0)
        {
            return n;
        }
        if(n%4==1)
        {
            return  1;
        }
        if(n%4==2)
        {
            return n+1;
        }
        return 0;
    }

    static long xor(long a,long b)
    {
        return xor(b)^xor(a-1);
    }


    

  
   
    

    
       
    

    
   
  



   

    static void printL(long a)
    {
        System.out.println(a);
    }
    static void printS(String s)
    {
        System.out.println(s);
    }

    static void printD(Double d)
    {
        System.out.println(d);
    }
  
   
   
    static void swap(char c,char p)
    {
        char t = c;
        c = p;
        p = t;
    }

    static long max(long n,long m)
    {
        return Math.max(n,m);
    }
    static long min(long n,long m)
    {
        return Math.min(n,m);
    }

    static double nd() throws IOException
    {
        return Double.parseDouble(in.next());
    }
    static int ni() throws IOException
    {
        return Integer.parseInt(in.next());
    }

    static long nl() throws IOException
    {
        return Long.parseLong(in.next());
    }

    static String si() throws IOException
    {
        return in.next();
    }


  
   
    static int abs(int n)
    {
        return Math.abs(n);
    }

    static class Scanner 
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException 
        {
            while (st == null || !st.hasMoreTokens()) 
            {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}
        
        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public boolean ready() throws IOException {return br.ready();}


    }

    
}



class Pair implements Comparable<Pair>
{
    int x;
    int y;
    public Pair(int x,int y)
    {
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair o)
    {
        return this.x-o.x;
    }
}