#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v)                               \
    cout << #v << "-->" << endl;               \
    for (auto it : v)                          \
    {                                          \
        cout << it.fi << " " << it.se << endl; \
    }
//#define mod 1000000007
#define mod 998244353
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int mI(int a, int m)
{
    return power(a, m - 2, m);
}
vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
#define double long double

int  t[4 * 200005];
void build(vector<int> &a, int v, int tl, int tr)
{
    if (tl == tr)
    {
        t[v] = a[tl]%mod;
    }
    else
    {
        int tm = (tl + tr) / 2;
        build(a, v * 2, tl, tm);
        build(a, v * 2 + 1, tm + 1, tr);
        t[v] = (t[v * 2]+ t[v * 2 + 1])%mod;
    }
}
int sum(int v, int tl, int tr, int l, int r)
{
    //db2(l, r);
    if (l > r)
        return 0;
    if (l == tl && r == tr)
    {
        return t[v]%mod;
    }
    int tm = (tl + tr) / 2;
    return (sum(v * 2, tl, tm, l, min(r, tm))+ sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r))%mod;
}
void update(int v, int tl, int tr, int pos, int new_val)
{
    if (tl == tr)
    {
        t[v] = new_val;
    }
    else
    {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v * 2, tl, tm, pos, new_val);
        else
            update(v * 2 + 1, tm + 1, tr, pos, new_val);
        t[v] = (t[v * 2]+ t[v * 2 + 1])%mod;
    }
}
void solve()
{
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> v(k);
    fo(i,k){
        cin >> v[i].fi >> v[i].se;
    }
    so(v);
    vec dp(n,0);
    dp[n - 1] = 1;
    build(dp, 1, 0, n - 1);
    for(int i = n - 2; i >= 0;i--){
        for (int j = 0; j < k;j++){
            if(i+v[j].fi>=n){
                break;
            }
            //db1(v[j].fi);
            //db1(i + v[j].fi);
            dp[i] += sum(1, 0, n - 1, i + v[j].fi, min(i +v[j].se, n - 1));
            dp[i] %= mod;
        }
        update(1, 0, n - 1, i, dp[i]);
    }
    //deb1a(dp);
    cout << dp[0];
}


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(0));

    // FILE *fin = freopen("ip.txt","r",stdin);
    // FILE *fout = freopen("op.txt","w",stdout);
    int t = 1, nn = 1;
    //cin >> t;
    while (t--)
    {
        // cout << "Case #" << nn << ":"
        //      << " ";
        // nn++;

        solve();
    }
}

Measured memory_bytes: 9004