using System;
using System.Collections.Generic;
using System.Linq;
using static ABC.Cin;
using static ABC.Cout;
using static ABC.Tool;


namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            Scanf(out int n, out int k);
            var L = new int[k];
            var R = new int[k];
            for(int i = 0; i < k; i++)
            {
                Scanf(out L[i], out R[i]);
            }

            var MOD = 998244353;
            var dp = new long[n + 1];
            dp[0] = 0;
            dp[1] = 1;

            var f = 0;
            for(int i = 0; i < k; i++)
            {
                if(L[i] == 1)
                {
                    f = 1;
                    break;
                }
            }

            if(f == 1)
            {
                dp[2] = 1;
            }
            else
            {
                dp[2] = 0;
            }

            for(int i = 3; i <= n; i++)
            {
                for(int j = 0; j < k; j++)
                {
                    if(i - L[j] > 0)
                    {
                        dp[i] = (dp[i] + dp[i - L[j]]) % MOD;
                    }
                    if(i - R[j] - 1 > 0)
                    {
                        dp[i] = (dp[i] - dp[i - R[j] - 1] + MOD) % MOD;
                    }
                }
                dp[i] += dp[i - 1];
                dp[i] %= MOD;
            }
            OutL(dp[n]);
        }
    }

    static class Cin
    {
        public static string[] ReadSplit => Console.ReadLine().Split();
        public static int[] ReadSplitInt => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadSplitLong => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string Str => Console.ReadLine();
        public static int Int => int.Parse(Console.ReadLine());
        public static long Long => long.Parse(Console.ReadLine());
        public static double Double => double.Parse(Console.ReadLine());
        public static T Conv<T>(string input)
        {
            return (T)Convert.ChangeType(input, typeof(T));
        }
        public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine());
        public static void Scanf<T,U>(out T a, out U b)
        {
            var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]);
        }
        public static void Scanf<T, U, V>(out T a, out U b, out V c)
        {
            var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]);
        }
        public static void Scanf<T, U, V, W>(out T a, out U b, out V c, out W d)
        {
            var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]);
        }
    }
    static class Cout
    {
        public static void OutL(object s) => Console.WriteLine(s);
    }
    static class Tool
    {
        public static long Gcd(long a, long b)
        {
            if (a % b == 0)
            {
                return b;
            }
            else
            {
                return Gcd(b, a % b);
            }
        }
        public static long Lcm(long a, long b) => a * b / Gcd(a, b);

        public static long[] PrimeFac(long n)
        {
            var result = new long[n + 1];
            for(int i = 2; i * i <= n; i++)
            {
                if (n % i != 0)
                {
                    continue;
                }

                var cnt = 0;
                while(n % i == 0)
                {
                    cnt++;
                    n /= i;
                }
                result[i] = cnt;
            }
            if(n != 1)
            {
                result[n] = 1;
            }
            return result;
        }
        public static long DivsCnt(long n)
        {
            var result = 1L;
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i != 0)
                {
                    continue;
                }

                var cnt = 0;
                while (n % i == 0)
                {
                    cnt++;
                    n /= i;
                }
                result *= (cnt + 1);
            }
            if (n != 1)
            {
                result *= 2;
            }
            return result;
        }
    }
}

Measured memory_bytes: 28856