using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 剩下的树
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] words = new string[100];
            words=s.Split(' ');
            int l = int.Parse(words[0]), m = int.Parse(words[1]);
            while (l != 0 || m != 0)
            {
                bool[] exist = new bool[10001];
                for (int i = 0; i <= l; i++)
                {
                    exist[i] = true;
                }
                while (m-- != 0)
                {
                    s = Console.ReadLine();
                    words = s.Split(' ');
                    int a = int.Parse(words[0]), b = int.Parse(words[1]);
                    for (int i = a; i <= b; i++)
                    {
                        exist[i] = false;
                    }
                }
                int cnt=0;
                for (int i = 0; i <= l; i++) 
                {
                    if (exist[i])
                        cnt++;
                }
                Console.WriteLine("{0}", cnt);
                s = Console.ReadLine();
                words = new string[100];
                words = s.Split(' ');
                l = int.Parse(words[0]);m = int.Parse(words[1]);
            }
        }
    }
}

/**************************************************************
	Problem: 2189
	User: admin
	Language: C#
	Result: Accepted
	Time:94 ms
	Memory:12888 kb
****************************************************************/