#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define MAX 100000
#define INF 1000000000
using ll=long long;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> L(K),R(K);
  for(int i=0;i<K;i++){
    cin>>L[i]>>R[i];
  }
  vector<ll> cnt(N,0);
  vector<ll> sum(N+1,0);
  cnt[0]=1;
  sum[0]=0;
  sum[1]=1;
  for(int i=1;i<N;i++){
    for(int j=0;j<K;j++){
      if(i-L[j]<0){
        continue;
      }
      cnt[i]+=sum[i-L[j]+1]-sum[max(i-R[j],0)]+MOD;
    }
    cnt[i]%=MOD;
    sum[i+1]=sum[i]+cnt[i];
    sum[i+1]%=MOD;
  }
  cout<<cnt[N-1]<<endl;
}
