#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;
const ll M = 998244353;

int main(){
  ll N,K;
  cin>> N >> K;
  ll L[K],R[K];
  //vector<ll> p;
  for(ll i=0;i<K;i++){
    cin >> L[i] >> R[i];
  }
  ll a[N+1];
  ll f[N+1];
  for(ll i=0;i<N+1;i++){
    f[i]=0;
    a[0]=0;
  }
  f[1] = 1;
  a[1] = 1;
  for(ll i=0;i<N+1;i++){
    for(ll j=0;j<K;j++){
      ll li = i-R[j];
      ll ri = i-L[j];
      if(ri<0) continue;
      if(li<1) li=1;
      f[i] += (a[ri] - a[li-1])%M;
    }
    a[i] = a[i-1]+f[i];
  }

  cout << f[N]%M << endl;
}
