#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

int main() {
    int64 mod = 998244353;
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> leg;
    for (int i=0; i<k; i++) {
        int l, r;
        cin >> l >> r;
        leg.emplace_back(l, r);
    }

    vector dp(n+1, 0);
    dp[1] = 1;

    for (int i=2; i<=n; i++) {
        for (auto j : leg) {
            for (int k=j.first; k<=j.second; k++) {
                if (i-k < 0)break;
                dp[i] = (dp[i] + dp[i-k]) % mod;
            }
        }
    }

    cout << dp[n] << endl;
}
