#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 998244353;
using Graph = vector<vector<int>>;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    int N,K;
    cin>>N>>K;
    int l[K],r[K];
    rep(i,K){
        cin>>l[i]>>r[i];
    }
    map<int,int> m;
    vector<int> v;
    rep(i,K){
        for(int j=l[i];j<=r[i];j++){
            m[j]++;
        }
    }
    for(auto p:m){
        v.push_back(p.first);
    }
    int dp[N+10]{};
    dp[1]=1;
    for(int i=1;i<=N+2;i++){
        for(auto p:v){
            if(i+p>N)break;
            dp[i+p]+=dp[i];
            dp[i+p]%=MOD;
        }
    }
    cout<<dp[N]<<endl;






}
