#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;

int main(int argc, char const *argv[])
{
    int mod = 998244353;
    int n, k; cin >> n >> k;
    //int step[200010] = {};
    //cout << step[3] << endl;
    int l[15], r[15];
    for (int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
    }
    
    sort(l,l+k);
    sort(r,r+k);
    rep(i,k) w[i] = r[i] - l[i];
    
    /*
    for (int i = 0; i < k; i++)
    {
        cin >> l >> r;
        for (int j = l; j <= r; j++)
        {
            step[j] = 1;
        }
    }
    */
    long long int dp[200010] = {};
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            if (l[j] >= i) break;
            for (int m = l[j]; m <= min(i,r[j]); m++)
            {
                dp[i] += dp[i-m];
                dp[i] %= mod;
            }
        }
    }
    cout << dp[n] << endl;


    

    return 0;
}
