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

namespace AtCoderBiginnerContest179
{
	class Program
	{
		private static int MOD = 998244353;

		static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var list = new List<int>();
			for (var i = 0; i < inputs[1]; i++)
			{
				var tmpInputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				list.AddRange(Enumerable.Range(tmpInputs[0], tmpInputs[1] - tmpInputs[0] + 1));
			}
			var set = list.OrderBy(x => x).ToArray();

			var array = new int[inputs[0]];
			array[0] = 1;
			for (var i = 1; i < inputs[0]; i++)
			{
				var tmp = 0;
				for (var j = 0; j < list.Count; j++)
				{
					if(i - set[j] < 0)
					{
						break;
					}

					tmp += array[i - set[j]];
					tmp %= MOD;
				}
				array[i] = tmp;
			}

			Console.WriteLine(array[inputs[0] - 1]);
		}
	}
}
