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

long long mod = 998244353;

int main(){
  long long N,K;
  cin >> N >> K;
  vector<long long> V(N*2+1,0),L(K),R(K);
  for(int i=0;i<K;i++) cin >> L[i] >> R[i];
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  V[0] = 1;
  V[1] = -1;
  
  for(int i=0;i<N;i++){
    for(int j=0;j<K;j++){
      V[i+L[j]] += V[i];
      V[i+L[j]] %= mod;
      
      V[i+R[j]+1] += mod;
      V[i+R[j]+1] -= V[i];
      V[i+R[j]+1] %= mod;
    }
    V[i+1] += V[i];
    V[i+1] %= mod;
  }
  
  cout << V[N-1] << endl;
  return 0;
}
