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

int main()
{
    int n, k;
    cin >> n >> k;
    set<int> s;
    int x, y;
    rep(i, k) {
        cin >> x >> y;
        y = min(y, n);
        for (int i=x; i<=y; i++) s.insert(i);
    }
    int len = s.size();
    long dp[n+1] = {0};
    dp[0] = 1;
    for (int i=1; i<n; i++) {
        for (int e : s) {
            if (i-e >= 0) dp[i] += dp[i-e];
        }
    }
    cout << dp[n-1]%mod << endl;
    // cout << dp[n-1] << endl;


    return 0;
}