using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Cryptography;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		//const int mod = 1000000007;  // 10^9+7
		const int mod = 998244353;
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			List<int> s = new List<int>();
			for (int i = 0; i < k; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				for (int j = vs[0]; j <= vs[1]; j++) {
					s.Add(j);
				}
			}
			s.Sort();
			//System.Diagnostics.Debug.WriteLine(string.Join(" ", s));
			int[] dp = new int[n + 1];
			dp[1] = 1;
			for (int i = 2; i <= n; i++) {
				for (int j = 0; j < s.Count; j++) {
					if (0 < i - s[j]) {
						dp[i] += dp[i - s[j]];
						dp[i] %= mod;
					} else {
						break;
					}
				}
			}
			//System.Diagnostics.Debug.WriteLine(string.Join(" ", dp));
			Console.WriteLine(dp[n]);

		}
	}
}
