#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll 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];
    }
    


    ll d[N]{};
    ll c[N + 1]{};
    d[0] = 1;
    c[1] = 1;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < K; j++) {
            int l = max(0, i - R[j]);
            int r = max(0, i - L[j] + 1);
            d[i] += c[r] - c[l];
            d[i] %= mod;
        }
        c[i + 1] = d[i] + c[i];
        c[i + 1] %= mod; 
    }
    cout << d[N - 1] << "\n";
    return 0;
}