#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,k,ans=0,mod=998244353;
  cin >> n >> k;
  vector<long> l(k),r(k),dp(n+1),ruisekiwa(n+1);
  for(long i=0;i<k;i++) cin >> l[i] >> r[i];
  dp[1]=1;
  ruisekiwa[1]=1;
  for(long i=2;i<=n;i++) {
    for(long j=0;j<k;j++) {
      dp[i]=(dp[i]+ruisekiwa[max(0L,i-l[j])]+mod-ruisekiwa[max(0L,i-r[j]-1)])%mod;
    }
    ruisekiwa[i]=(ruisekiwa[i-1]+dp[i])%mod;
  }
  cout << dp[n] << endl;
}