#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6;
const int MOD = 998244353;
struct D {
  int l, r;
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> w;
  vector<D> x(k);
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> x[i].l >> x[i].r;
  }
  vector<long int> p(n + 1, 0);
  p[1] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < x.size(); ++j) {
      for (int l = x[j].l; l <= x[j].r; ++l) {
        if (i + l > n) {
          break;
        } else {
          p[i + l] += p[i];
          if (p[i + l] >= MOD) p[i + l] %= MOD;
        }
      }
    }
  }
  cout << p[n] << endl;
  return 0;
}
