using System;
class Program
{
	static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);

        bool[] enable = new bool[N+1];
        int enableMax = 0;
        for (int i = 0; i < K; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            int L = int.Parse(inputs[0]);
            int R = int.Parse(inputs[1]);

            if(R > enableMax)
            {
                enableMax = R;
            }

            for (int j = L; j <= R; j++)
            {
                enable[j] = true;
            }

        }

        int[] route = new int[N+1];
        route[1] = 1;
        for (int i = 2; i <= N; i++)
        {
            for (int j = 1; j < i; j++)
            {
                if(enable[i-j])
                {
                    if((route[i] + route[j]) < 998244353)
                    {
                        route[i] += route[j];
                    }
                    else
                    {
                        route[i] += route[j] - 998244353;
                    }
                }
            }
        }
		//出力
		Console.WriteLine(route[N]%998244353);
	}
}