#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> dp(n);
  vector<ll> l(k);
  vector<ll> r(k);
  ll M=998244353;
  rep(i,k){
    cin >> l[i] >> r[i];
  }
  rep(i,n){
    if(i==0){
      dp[i]=1;
    }else{
      dp[i]=dp[i-1];
      rep(j,k){
        if (i-r[j]-1>=0){
          dp[i]+=dp[i-l[j]];
          dp[i]-=dp[i-r[j]-1];
        }else if(i-l[j]>=0){
          dp[i]+=dp[i-l[j]];
        }
      }
      dp[i]=(dp[i]+M)%M;
    }
  }
  ll res= (dp[n-1]-dp[n-2]+M)%M;
  cout << res << endl;
  return 0;
}
