using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    public static void Main()
    {
        int n = ReadInt();
        int k = ReadInt();
        var s = new List<(int, int)>();
        for (int i = 0; i < k; i++)
        {
            s.Add((ReadInt(), ReadInt()));
        }
        var dp = new Segtree<ModInt>(n, (i, j) => i + j, 0);
        dp.update(0, 1);
        for (int i = 0; i < n; i++)
        {
            foreach (var (l, r) in s)
            {
                dp.update(i, dp.look(i) + dp.run(i - r, i - l + 1));
            }
        }
        Console.WriteLine((int)dp.look(n - 1));
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
}

class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex)
    {
        for (int i = 0; i < m; ++i) tree[i + n - 1] = ini;
        all_update();
    }
    public void assign_without_update(int j, T x)
    {
        tree[j + n - 1] = x;
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public void all_update()
    {
        for (int i = n - 2; i >= 0; i--)
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t)
    public T run(int s, int t) { return query(s, t, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

struct ModInt
{
    const int MOD = 998244353;// 1000000007;
    long value;
    static List<ModInt> fact = new List<ModInt> { 1 };
    public ModInt(long value) => this.value = value;
    public static implicit operator ModInt(long a) => new ModInt(a % MOD + (a < 0 ? MOD : 0));
    public static explicit operator int(ModInt a) => (int)a.value;
    public static ModInt operator +(ModInt a, ModInt b) => a.value + b.value;
    public static ModInt operator -(ModInt a, ModInt b) => a.value - b.value;
    public static ModInt operator *(ModInt a, ModInt b) => a.value * b.value;
    public static ModInt operator /(ModInt a, ModInt b) => a * Inv(b);
    public static ModInt Pow(ModInt a, int n) { if (n == 0) return 1; if (n == 1) return a; var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); }
    public static ModInt Inv(ModInt a) => Pow(a, MOD - 2);
    public static ModInt Fact(int n) { for (int i = fact.Count; i <= n; i++) fact.Add(fact[^1] * i); return fact[n]; }
    public static ModInt Npr(int n, int r) => Fact(n) / Fact(n - r);
    public static ModInt Ncr(int n, int r) => Fact(n) / Fact(n - r) / Fact(r);
    public static ModInt Nhr(int n, int r) => Fact(n + r - 1) / Fact(n - 1) / Fact(r);
}


Measured memory_bytes: 32632