#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long dp[200007] = {};
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> c(n + 1), d(n + 1), e;
  d[0] = 0;
  for (int i = 0; i < (int)(k); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    c[a] = 1;
    c[b + 1] = -1;
  }
  for (int i = 0; i < (int)(n); i++) d[i + 1] = d[i] + c[i];
  for (int i = 0; i < (int)(n + 1); i++) {
    if (d[i] > 0) e.push_back(i);
  }
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (auto j : e) {
      if (i - j < 0) continue;
      dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }
  cout << dp[n - 1] << endl;
}
