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

using E = System.Linq.Enumerable;

public class Program
{
    const int Mod = 998244353;

    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (n, k) = (nk[0], nk[1]);
        var lengthSum = 0;
        var segments = new (int L, int R)[k];
        for (int i = 0; i < segments.Length; ++i)
        {
            var s = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            segments[i] = (s[0], s[1]);
            lengthSum += s[1] - s[0] + 1;
        }

        Array.Sort(segments);

        var ds = new List<int>(lengthSum);
        for (int i = 0; i < segments.Length; ++i)
        {
            var (offset, length) = new Range(segments[i].L, segments[i].R + 1).GetOffsetAndLength(n + 1);
            ds.AddRange(E.Range(offset, length));
        }

        var dp = new int[n];
        dp[0] = 1;
        for (int i = 1; i < dp.Length; ++i)
        {
            for (int j = 0; j < ds.Count; ++j)
            {
                if (ds[j] > i)
                {
                    break;
                }

                dp[i] += dp[i - ds[j]]; dp[i] %= Mod;
            }
        }

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