using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 998244353;//1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            if(ret != null) Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var k = int.Parse(spl[1]);

        int[] xx = new int[n+1];

        for(int i=0; i<k; i++) {
            spl = input.ReadLine().Split(' ');
            var l = int.Parse(spl[0]);
            var r = int.Parse(spl[1]);
            for(int j=l; j<=r; j++) {
                xx[j] = 1;
            }
        }

        long[] yy = new long[n+1];

        for(int i=n-1; i>=1; i--) {
            if(xx[n-i] == 1) yy[i] += 1;
            for(int j=1; j<=n-i-1; j++) {
                if(xx[j] == 1) {
                    yy[i] += yy[i+j];
                    yy[i] %= Mod;
                }
            }
        }

        return yy[1];
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}
