#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
//int mod = 1e9 + 7;
int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

int n, k;
vector<int> v;
int dp[2 * N];
int fun(int cur)
{
    if (cur > n)
        return 0;
    if (cur == n)
        return 1;
    if (dp[cur] != -1)
        return dp[cur];
    int ans = 0;
    for (int i : v)
    {
        if (cur + i > n)
            break;
        ans += fun(cur + i) % mod;
        ans %= mod;
    }
    return dp[cur] = ans;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            v.pb(j);
    }
    sort(all(v));
    memset(dp, -1, sizeof(dp));
    cout << fun(1) << "\n";
}
int32_t main()
{
    AB_BHI_NI_DEGI
    int Test = 1;
    //cin >> Test;
    //init();
    while (Test--)
        solve();
    return 0;
}
/*

*/