#include <bits/stdc++.h>
long long DENOM = 1000000000LL + 7LL;
long long DEN2 = 998244353LL;
using namespace std;
long long n, m, k;
long long h, w;
int main() {
  cin >> n >> k;
  vector<pair<long long, long long> > lr;
  for (int i = 0; i < k; ++i) {
    long long l, r;
    cin >> l >> r;
    lr.push_back(make_pair(l, r));
  }
  vector<long long> res(n, 0);
  res[0] = 1;
  for (int i = 1; i < n; ++i) {
    for (auto it = lr.begin(); it != lr.end(); ++it) {
      long long l, r;
      l = it->first;
      r = it->second;
      for (int j = l; j < r + 1; ++j) {
        if (i - j < 0) break;
        res[i] += res[i - j];
        res[i] %= DEN2;
      }
    }
  }
  cout << res[n - 1] << endl;
  return 0;
}
