#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=998244353;
const long long INF = 1LL<<60;

int main() {
  int64_t N,K,T=0; cin>>N>>K;
  vector<int64_t> R(2*K);
  rep(i,2*K){
    cin>>R[i];
    if(i%2==1)R[i]++;
  }
  vector<int64_t> DP(N,0);
  DP[0]=1;
  for(int64_t i=0;i<N;i++){
    if(i>1)DP[i]+=DP[i-1];
    DP[i]%=MOD;
    auto k=DP[i];
    rep(j,2*K){
      auto r=R[j];
      if(i+r>=N) continue;
      if(j%2==0){
        DP[i+r]+=k;
        DP[i+r]%=MOD;
      }
      else if(j%2==1){
        DP[i+r]-=k;
      }
    }
  }
  cout<<(DP[N-1]+MOD)%MOD;
}

