import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    }
} import java.util.*; util.* java public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    }
} Main public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc final int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int lMax = Integer.MIN_VALUE; lMax Integer.MIN_VALUE Integer Integer.MIN_VALUE int rMin = Integer.MAX_VALUE; rMin Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        } int i = 0; int i = 0; i 0 i<m i m ++i ++i i {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        } {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if (lMax < l) lMax = l; lMax < l lMax l lMax = l lMax l if (rMin > r) rMin = r; rMin > r rMin r rMin = r rMin r int count = 0; count 0 for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count; int i = 0; int i = 0; i 0 i<=n i n ++i ++i i if (lMax <= i && rMin >= i) ++count; if (lMax <= i && rMin >= i) ++count; lMax <= i && rMin >= i lMax <= i lMax i rMin >= i rMin i ++count count System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    }
} public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    }
} Main
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int m = sc.nextInt();
        int lMax = Integer.MIN_VALUE;
        int rMin = Integer.MAX_VALUE;

        for (int i = 0;i<m;++i)
        {
            int l = sc.nextInt();
            int r = sc.nextInt();
            if (lMax < l) lMax = l;
            if (rMin > r) rMin = r;
        }

        int count = 0;
        for (int i = 0;i<=n;++i) if (lMax <= i && rMin >= i) ++count;

        System.out.println(count);
        sc.close();
    }
}