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