#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> lr;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j < r + 1; ++j) {
      lr.push_back(j);
    }
  }
  sort(lr.begin(), lr.end());
  vector<int> dp(n);
  dp[0] = 1;
  for (int i = 1; i < n; ++i) {
    for (int x : lr) {
      if (x > i) continue;
      dp[i] += dp[i - x];
      dp[i] %= mod;
    }
  }
  cout << dp[n - 1] << endl;
}
