#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); ++(i))
typedef long long ll;
const int INF = 1001001001;
const int LIMIT = 998244353;

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> s;
    int l,r;
    rep(j,k){
        cin>>l>>r;
        for (int i = l-1; i < r; i++)s.push_back(i+1);
    }

    vector<ll> dp(n+1,0);
    rep(i,s.size())dp[s[i]-1]=1;
    int b=s.size();
    rep(i,n){
        for(int j=0; j<b; j++){
            if(i-s[j]>=0){
                dp[i]+=dp[i-s[j]];

                }

        }

    }
    dp[i]%=LIMIT;
    cout<<dp[n-2]<<endl;
    return 0;
}

//5 2
//1 1
//3 4

//4