import javax.management.monitor.CounterMonitor;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    }
} import javax.management.monitor.CounterMonitor; CounterMonitor javax.management.monitor import java.math.BigDecimal; BigDecimal java.math import java.util.*; util.* java public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    }
} Main public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    } main {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    } int count = 0; count 0 boolean sw = false; sw false int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int answer=0; answer 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int M =sc.nextInt(); M sc.nextInt() sc.nextInt sc int L[]=new int[M]; L new int[M] M int R[]=new int[M]; R new int[M] M for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        } {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        } L[i]=sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i]=sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            } i==0 i 0 {
                min=L[i];
                max=R[i];
            } min=L[i] min L[i] L i max=R[i] max R[i] R i if(L[i]>min)
            {
                min=L[i];
            } L[i]>min L[i] L i min {
                min=L[i];
            } min=L[i] min L[i] L i if(R[i]<max)
            {
                max=R[i];
            } R[i]<max R[i] R i max {
                max=R[i];
            } max=R[i] max R[i] R i answer=max-min+1 answer max-min+1 max-min max min 1 if(answer<0)
        {
            answer=0;
        } answer<0 answer 0 {
            answer=0;
        } answer=0 answer 0 System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    }
} public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    }
} Main
import javax.management.monitor.CounterMonitor;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Euclid e1=new Euclid();//ユークリッドの互除法
        //Compute c1=new Compute();//累積和，
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        int answer=0;
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M =sc.nextInt();
        int L[]=new int[M];
        int R[]=new int[M];
        for(int i=0;i<M;i++)
        {
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            if(i==0)
            {
                min=L[i];
                max=R[i];
            }else if(L[i]>min)
            {
                min=L[i];
            }
            if(R[i]<max)
            {
                max=R[i];
            }
        }
        //System.err.println("min"+min);
        //System.err.println("max"+max);
        answer=max-min+1;
        if(answer<0)
        {
            answer=0;
        }



        //出力
        //System.err.println();//標準エラー出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        System.out.println(answer);
    }
}