#include <bits/stdc++.h>
using namespace std;
class DLeapingTak {
 public:
  void solve(std::istream& in, std::ostream& out) {
    long long int n, k;
    in >> n >> k;
    long long int mo = 998244353;
    vector<long long int> m(n + 1, 0);
    vector<int> s;
    for (long long int i = 0; i < (k); ++i) {
      int l, r;
      in >> l >> r;
      for (int j = l; j <= r; j++) {
        s.push_back(j);
      }
    }
    sort(s.begin(), s.end());
    m[1] = 1;
    for (int i = 1; i < n; i++) {
      if (m[i] == 0) continue;
      auto e = lower_bound(s.begin(), s.end(), n - i + 1);
      for (auto j = s.begin(); j != e; j++) {
        int t = *j;
        if (t + i <= n) {
          m[t + i] += m[i];
          m[t + i] %= mo;
        }
      }
    }
    out << m[n] << endl;
  }
};
int main() {
  DLeapingTak solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
