#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> range(n + 1, 0);
  vector<pair<int, int>> v;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
    range[x]++;
    range[y + 1]--;
  }
  for (int i = 1; i <= n; i++) {
    range[i] = range[i - 1] + range[i];
  }
  vector<int> poss;
  for (int i = 1; i <= n; i++) {
    if (range[i] >= 1) {
      poss.push_back(i);
    }
  }
  vector<int> dp(n + 1, 0);
  for (int i = 0; i < poss.size(); i++) {
    dp[poss[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < poss.size(); j++) {
      if (poss[j] <= i) {
        dp[i] = (dp[i] % mod + dp[i - poss[j]] % mod) % mod;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
