#include <bits/stdc++.h>
constexpr long long INFLL = 1e18;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  const int mPN = 998244353;
  int n, k;
  cin >> n >> k;
  int l, r;
  vector<int> v;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end());
  vector<int> dp(n, 0);
  dp.at(0) = 1;
  int temp;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < v.size(); j++) {
      temp = i - v.at(j);
      if (temp >= 0 && temp < n) {
        dp.at(i) += dp.at(temp);
        dp.at(i) %= mPN;
      }
      if (temp < 0) {
        break;
      }
    }
  }
  cout << dp.at(n - 1) << endl;
  return 0;
}
