#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> w;
  long long dp[200005] = {0};
  int min = 200005;
  for (int i = 0; i < (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) {
      if (i < min) min = i;
      w.push_back(i);
      dp[i] = 1;
    }
  }
  int s = w.size();
  for (int i = min - 1; i <= n - min; i++) {
    for (int j = 0; j < (s); j++) {
      if (i - w[j] >= 0) {
        dp[i] += dp[i - w[j]];
        dp[i] %= 998244353;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
