using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5 2");
            WillReturn.Add("1 1");
            WillReturn.Add("3 4");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 2");
            WillReturn.Add("3 3");
            WillReturn.Add("5 5");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 1");
            WillReturn.Add("1 2");
            //5
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("60 3");
            WillReturn.Add("5 8");
            WillReturn.Add("1 3");
            WillReturn.Add("10 15");
            //221823067
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    const int Hou = 998244353;
    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int N = wkArr[0];

        var DSet = new HashSet<int>();

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);

            int L = wkArr[0];
            int R = wkArr[1];
            for (int I = L; I <= R; I++) {
                DSet.Add(I);
            }
        }
        int[] AscDArr = DSet.OrderBy(pX => pX).ToArray();

        //場合の数[現在位置]
        int UB = N;
        int[] DPArr = new int[UB + 1];
        DPArr[1] = 1;

        for (int I = 1; I <= UB; I++) {
            if (DPArr[I] == 0) continue;
            foreach (int EachInt in AscDArr) {
                int NewInd = I + EachInt;
                if (UB < NewInd) break;
                DPArr[NewInd] += DPArr[I];
                DPArr[NewInd] %= Hou;
            }
        }
        Console.WriteLine(DPArr[UB]);
    }
}
