using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		int[,]A = new int[K,2];
		for(var i=0;i<K;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0]);
			A[i,1] = int.Parse(str2[1]);
		}
		long[]D = new long[N+1];
		D[0] = 1;
		long mod = 998244353;
		for(var i=0;i<N;i++){
			if(D[i]>0){
				for(var j=0;j<K;j++){
					for(var k=Math.Min(N-i,A[j,0]);k<=Math.Min(N-i,A[j,1]);k++){
						D[i+k] = D[i+k] + D[i];
						D[i+k] %= mod;
					}
				}
			}
		}
		//for(var i=0;i<=N;i++){
        //  	Console.Error.Write(D[i]+" ");
        //}
		Console.WriteLine(D[N-1]);
	}
}