#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> range;
  int l, r;
  for (int i = 0; i < (k); ++i) {
    cin >> l >> r;
    for (int j = l; j != (r + 1); ++j) {
      range.push_back(j);
    }
  }
  vector<int> dp(n + 1, 0);
  for (int j : range) {
    dp[n - j]++;
  }
  for (int i = n; i != -1; --i) {
    if (dp[i] == 0) continue;
    for (int j : range) {
      if (i - j < 0) continue;
      dp[i - j] += dp[i];
      dp[i - j] %= 998244353;
    }
  }
  cout << dp[1] << endl;
  return 0;
}
