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

#define ll long long int
#define All(a) (a).begin(),(a).end()

// Remember v.shrink_to_fit() when erasing
ll cnt=0,M=998244353;
int n;
vector<int> v;
vector<int> diff;


void solve(){
  int k,l,r,t,x,y;
  cin >>n>>k;
  for(int i=0;i<k;i++){
    cin>>l>>r;
    v.push_back(l);
    diff.push_back(r);
  }
  ll dp[n+1]={};
  ll C_sum[n+1]={};
  dp[1]=1;
  C_sum[1]=1;
  for(int i=2; i <= n; i++){
    for(int j=0; j <v.size(); j++){
      x=max({0,i-v[j]});
      y=max({0,i-diff[j]-1});
      ll tmp=(C_sum[x]-C_sum[y]);
      tmp%=M;
      dp[i]=(dp[i]+tmp)%M;
    }
    C_sum[i]=(C_sum[i-1]+dp[i])%M;
  }
  printf("%lld\n",dp[n]);
}
int main(){

  solve();

  return 0;
}