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

#define INF 1001001001
#define MAX 1e18

const int mod = 998244353;

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