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 array = new int?[inputs[0]];
			array[0] = 1;

			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();

			int CulcurateRoute(int n)
			{
				if (array[n] != null)
				{
					return array[n].Value;
				}

				if (n - set[0] < 0)
				{
					array[n] = 0;
					return 0;
				}

				var tmp = 0;
				for (var i = 0; i < set.Length; i++)
				{
					if (n - set[i] < 0)
					{
						break;
					}
					tmp += CulcurateRoute(n - set[i]);
					tmp %= MOD;
				}
				array[n] = tmp;
				return tmp;
			}


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

	}
}
