#include <iostream>
#include <vector>
using namespace std;
const int MOD = 998244353;
int main() {
    int n, k;
    cin >> n >> k;
    int l[k], r[k];
    for (int i=0; i<k; i++) {
        cin >> l[i] >> r[i];
    }
    int f[n] = {};
    f[0] = 1;
    for (int i=1; i<n; i++) {
        for (int j=0; j<k; j++) {
            for (int d=l[j]; d<=r[j]; d++) {
                if (i-d >= 0) {
                    f[i] += f[i-d];
                    f[i] %= MOD;
                } else {
                    break;
                } 
            }
        }
    }
    cout << f[n-1] << endl;
}