using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder.Probrems.Solvers.ABC127
{
    public class C
    {
        static void Main(string[] args)
        {
            var nm = ReadLine().Split().Select(int.Parse).ToArray();
            var gates = Enumerable.Range(0, nm[1]).Select(_ => ReadLine().Split());
            WriteLine(Solve(nm[0], nm[1], gates));
        }

        public static long Solve(int n, int m, IEnumerable<string[]> gates)
        {
            int h = 0;
            int t = int.MaxValue;
            foreach (var gate in gates)
            {
                h = Math.Max(int.Parse(gate[0]), h);
                t = Math.Min(int.Parse(gate[1]), t);
                if (h > t)
                    return 0;
            }

            return t - h + 1;
        }

        private const int MOD = 1000000007;
    }
}
