#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#define ll long long
using namespace std;
constexpr auto mod=998244353;
ll dp[200000*2+5];
vector<pair<ll,ll>> v;
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        int a,b;
        cin>>a>>b;
        v.emplace_back(make_pair(a,b));
    }
    dp[1]=1;
    dp[2]=-1;
    for(int i=1;i<=n;i++){
        dp[i]=((dp[i]+dp[i-1])%mod+mod)%mod;
        for(int j=0;j<k;j++){
            dp[i+v[j].first]=dp[i+v[j].first]+dp[i];
            dp[i+v[j].second+1]=dp[i+v[j].second+1]-dp[i];
        }
    }
    cout<<dp[n]<<endl;
    //getchar();
    //getchar();
    return 0;
}