#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
int main() {
  ull n, k;
  cin >> n >> k;
  vector<pair<ull, ull>> s(k, {0, 0});
  for (ull i = 0; i < k; ++i) {
    ull l, r;
    cin >> l >> r;
    s[i] = {l, r};
  }
  vector<int> total(n + 1, 0);
  total[1] = 1;
  for (ull i = 1; i < n; ++i) {
    for (auto p : s) {
      for (ull k = p.first; k <= p.second; ++k) {
        if (i + k < n + 1) {
          total[i + k] = (total[i + k] + total[i]) % 998244353;
        }
      }
    }
  }
  cout << total[n] << endl;
  return 0;
}
