using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramD a = new ProgramD();
            a.main();//実行する

        }

    }
    //ABC178
    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();
            //30以上ならYes、それ以外はNoを出力
            if(s[s.Length  -1] == 's')
                Console.WriteLine(s + "es");
            else
                Console.WriteLine(s + "s");


        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            int n = int.Parse(Console.ReadLine());
            int[] zorome = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                if (int.Parse(s[0]) == int.Parse(s[1]))
                    zorome[i] = 1;
                else
                    zorome[i] = 0;
            }
            int count = 0;
            for(int i = 0;i < n;i++)
            {
                if (zorome[i] == 1)
                    count++;
                else
                    count = 0;

                if (count == 3)
                {
                    Console.WriteLine("Yes");
                    return;
                }

            }
            
            Console.WriteLine("No");

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());

            long count = 0;
            for(int i = 1;i < n;i++)
            {
                count += (n - 1) / i;
            }

            Console.WriteLine(count);

        }

    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long k = long.Parse(s[1]);
            long MOD = 998244353;

            long[] dp = new long[n];
            List<long> list = new List<long>();

            for(int i = 0; i < k;i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = int.Parse(t[0]); j <= int.Parse(t[1]); j++)
                    list.Add(j);
            }
            list.Sort();
            dp[0] = 1;
            int num = list.Count();
            for (int i = 0; i < n;i++)
            {
                for (int j = 0; j < num; j++)
                {
                    long temp = list[j];
                    if(temp + i < n)
                    {
                        dp[temp + i] += dp[i];
                        dp[temp + i] %= MOD;
                    }
                }
                
                
            }

            Console.WriteLine(dp[n - 1]);

        }
            
    }

    class ProgramE
    {

        public void main()
        {

        }


    }

}




