using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC179D
{
    class Program
    {
        static long ans = 0;
        static long mod= 998244353;
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            long N = long.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            bool[] hantei = new bool[200001];
            hantei[0] = true;
            for(int i = 0; i < K; i++)
            {
                string[] LR = Console.ReadLine().Split(' ');
                long L = long.Parse(LR[0]);
                long R = long.Parse(LR[1]);
                for(long j = L; j <= R; j++)
                {
                    hantei[j] = true;
                }
            }
            //Console.WriteLine(string.Join(" ", S));

            long[] ans = new long[N + 1];
            ans[0] = 1;
            for(int i = 1; i <= N; i++)
            {
                for(int d = 1; d <= i; d++)
                {
                    if (hantei[d])
                    {
                        ans[i] += ans[i - d];
                        ans[i] %= mod;
                    }
                }
            }
            Console.WriteLine(ans[N-1]);
        }
    }
}
