#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main() {
  int N,K,i,j,MOD=998244353;
  cin>>N>>K;
  vector<int> L(K),R(K);
  for (i=0;i<K;i++) {
    cin>>L[i]>>R[i];
  }
  vector<ll> dp(N+1, 0), dps(N+1,0);
  dp[0]=0;dp[1]=1;
  dps[0]=0;dps[1]=1;
  for (i=2;i<=N;i++) {
    for (j=0;j<K;j++) {
      int r = i-L[j];
      int l = max(i-R[j],1);
      if (0<r) {
        dp[i] += (dps[r] - dps[l-1] + MOD) % MOD;
        dp[i] %= MOD;
      }
    }
    dps[i] = (dps[i-1] + dp[i]) % MOD;
  }
  cout<<dp[N]<<endl;
  return 0;
}
