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