#include <iostream>
using namespace std;
using ll = __int128_t;
ll dp[1000005] = {0};
pair<int, int> p[10];
int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < k; ++i)
    {
        cin >> p[i].first >> p[i].second;
    }
    ll cur = 1;
    for (int i = 1; i < n; ++i)
    {
        cur += dp[i];
        for (int j = 0; j < k; ++j)
        {
            if (i + p[j].first <= n)
            {
                dp[i + p[j].first] += cur;
                dp[i + p[j].second + 1] -= cur;
            }
        }
    }
    cout << dp[n] % 998244353;
}