#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

const ull M = 998244353;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ull> l(k), r(k);
    for(int i = 0; i < k; i++) {
        cin >> l[i] >> r[i];
    }
    vector<ull> ans(n, 0);
    ans[0] = 1;
    ull s = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < k; j++) {
            if (i >= l[j]) {
                s = (s + ans[i-l[j]]) % M;
            }
            if (i > r[j]) {
                s = (s + M - ans[i-r[j]-1]) % M;
            }
        }
        ans[i] = s;
    }
    cout << s << endl;
    return 0;
}
