#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> L(K),R(K);
  int i,j;
  for(i=0;i<N;i++)cin >> L[i] >> R[i];
  vector<long long> w(N+1,0),s(N+2);
  s[N+1] = 0;
  w[N] = s[N] = 1;
  for(i=0;i<N;i++) {
    for(j=0;j<K;j++) {
      if(L[j]-i-1 <= 0)w[N-i-1] = (w[N-i-1] + s[N-i-1+L[j]]-s[min(N+1,N-i+R[j])] + 998244353)%998244353;
    }
    s[N-i-1] = (s[N-i]+w[N-i-1])%998244353;
  }
  cout << w[1] << endl;
}