#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int dp[200100],imos[200100];
signed main(){
  int N,K;
  cin>>N>>K;
  vector<pair<int,int>> A(K);
  for(pair<int,int> &p:A)cin>>p.first>>p.second;
  dp[1]=1;
  for(int i=1;i<=N;i++){
    imos[i]=(imos[i]+imos[i-1])%mod;
    dp[i]=(dp[i]+imos[i])%mod;
    for(pair<int,int> p:A)
      imos[i+p.first]=(imos[i+p.first]+dp[i])%mod,imos[i+p.second+1]=(imos[i+p.second+1]-dp[i]+mod)%mod;
  }
  cout<<dp[N]<<endl;
}