#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int j = 0; j < (k); j++) cin >> l[j] >> r[j];
  vector<int> dp(n + 1, 0);
  vector<int> dpsum(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (k); j++) {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri < 0) continue;
      li = max(1, li);
      dp[i] += dpsum[ri] - dpsum[li - 1];
      dp[i] %= MOD;
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
    dpsum[i] %= MOD;
  }
  cout << (dp[n] + MOD) % MOD << endl;
  return 0;
}
