using System;
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine(); //標準入力
        string[] aa = a.Split(' ');


        int N = int.Parse(aa[0]);
        int K = int.Parse(aa[1]);

        int[] L = new int[K];
        int[] R = new int[K];
        bool[] S = new bool[N];


        for (int i = 0; i < N; i++)
        {
            S[i] = false;
        }


        for (int i = 0; i < K; i++)
        {
            string lr = Console.ReadLine();
            string[] lri = lr.Split(' ');
            L[i] = int.Parse(lri[0]);
            R[i] = int.Parse(lri[1]);
            for (int j = L[i] - 1; j < R[i]; j++)
            {
                S[j] = true;
            }
        }


        decimal[] count = new decimal[N];
        count[0] = 1;
        for (int i = 1; i < N; i++)
        {
            
            for (int j = 0; j <i; j++)
            {
                if (S[j])
                {
                    count[i] += count[i - j-1];
                    count[i] = count[i] % (decimal)998244353;
                }
            }
        }

        for (int i = 0; i < N; i++)
        {

            //Console.WriteLine("{0}", count[i]);

        }
        Console.WriteLine("{0}", count[N-1]);

    }

}