#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  vector<int> a(n + 1, 0);
  a[1] = 1;
  a[2] = -1;
  uint64_t dpsum = 0;
  for (int i = 1; i < n; i++) {
    dpsum += a[i];
    for (int j = 0; j < k; j++) {
      if (i + l[j] <= n) {
        a[i + l[j]] += dpsum;
      }
      if (i + r[j] + 1 <= n) {
        a[i + r[j] + 1] -= dpsum;
      }
    }
  }
  uint64_t sum = accumulate(a.begin(), a.end(), 0LL) % 998244353;
  cout << sum << endl;
}
