#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

constexpr int MOD = 998244353;
#include "atcoder/lazysegtree"
using namespace atcoder;

int op(int l, int r)
{
    return (l + r) % MOD;
}

int e()
{
    return 0;
}

int mapping(int l, int r)
{
    return (l + r) % MOD;
}

int composition(int l, int r)
{
    return (l + r) % MOD;
}

int id()
{
    return 0;
}

int main()
{
    int N, K;
    io >> N >> K;

    int L[10], R[10];
    for (int i = 0; i < K; i++)
    {
        io >> L[i] >> R[i];
        R[i]++;
    }
    
    lazy_segtree<int, op, e, int, mapping, composition, id> seg(N);
    seg.set(0, 1);

    for (int i = 0; i < N; i++)
    {
        int ai = seg.get(i);
        for (int k = 0; k < K; ++k)
        {
            if (i + L[k] < N)
            {
                seg.apply(i + L[k], min(i + R[k], N), ai);
            }
        }
    }
    
    io << seg.get(N-1) << BR;
}