#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k2;
  cin >> n >> k2;
  set<int> s;
  int dp[n];
  for (int i = 0; i < n; i++) {
    dp[i] = 0;
  }
  dp[0] = 1;
  int l[k2], r[k2];
  for (int i = 0; i < k2; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j <= r[i]; j++) {
      s.insert(j);
    }
  }
  for (int k = 0; k < n; k++) {
    auto idx = s.begin();
    while (idx != s.end()) {
      int j = *idx;
      if (k + j >= n) break;
      if (dp[k] != 0) {
        dp[k + j] += dp[k];
        dp[k + j] %= 998244353;
      }
      idx++;
    }
  }
  cout << dp[n - 1] << endl;
}
