#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k, 0), r(k, 0);
  for (int i = 0; i < (k); i++) cin >> l.at(i) >> r.at(i);
  vector<int> b(n + 1, 0), c(n + 1, 0);
  c.at(1) = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (k); j++) {
      int L = l.at(j) + i, R = min(n, r.at(j) + i + 1);
      if (L < n)
        b.at(L) = (int)(((long long)b.at(L) + (long long)c.at(i)) % 998244353);
      b.at(R) -= c.at(i);
      if (b.at(R) < 0) b.at(R) += 998244353;
    }
    c.at(i + 1) = (c.at(i) + b.at(i)) % 998244353;
  }
  cout << c.at(n);
}
