#include <bits/stdc++.h>
#include <vector>
#include <limits>
using namespace std;

#define LL long long int
#define rep(k, n) for(LL i=k;i<n;++i)
#define INF numeric_limits<int>::max() // double INF numeric_limits<double>::infinity()
//#define N 100001
#define MAXN 10001
//vector<vector<int>> ans;

vector<int> steps;

void solve(int n){
    LL ways[n+1]{0};
    ways[1] = 1;
    for(int i=2; i<= n; ++i){
        for(int j=0; j< steps.size(); ++j){
            if(steps[j] < i) ways[i] += ways[i-steps[j]];
        }
    }
    cout<< (ways[n] % 998244353)<< endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
    int n, k; cin>>n >> k;
    int a, b;

    while(k--){
        cin>> a>> b;
        for(int i=a; i<= b; ++i) steps.push_back(i);
    }
    cout<< endl;
    solve(n);


}