using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (N, K) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var LR = Range(0, K).Select(i => ReadLine().Split(' ').Select(int.Parse).ToArray()).ToArray();

        var mod = 998244353L;
        var dp = new long[N + 1];
        dp[1] = 1;

        for (int i = 1; i <= N; i++)
        {
            foreach (var (L, R) in LR)
            {
                for (int j = L; j <= R; j++)
                {
                    if (i + j > N)
                        break;
                    dp[i + j] = (dp[i + j] + dp[i]) % mod;
                }
            }
        }

        WriteLine(dp[N]);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}
