#include <bits/stdc++.h>
using namespace std;

long long MOD = 998244353;
int main()
{
    int n, k; cin >> n >> k;
    vector<pair<int, int> > seg;
    for (int i = 0; i < k; i++)
    {
        int l, r; cin >> l >> r;
        seg.push_back({l, r});
    }
    vector<long long> ans(n+1), sum(n+1);
    ans[1] = 1; sum[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            ans[i] += (MOD + sum[max(0, i-seg[j].first)] - sum[max(0, i-seg[j].second - 1)]) % MOD;
            ans[i] %= MOD;
        }
        sum[i] = sum[i-1] + ans[i]; sum[i] %= MOD;
    }
    cout << ans[n] << '\n';
}
