#include <bits/stdc++.h>
using namespace std;
int main() {
  const int mod = 998244353;
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
  }
  vector<long> c(n, 0);
  c[0] = 1;
  int first, last;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      first = max(i - r[j], 0);
      last = max(i - l[j], -1);
      for (int m = first; m <= last; ++m) {
        c[i] += c[m];
      }
      c[i] %= mod;
    }
  }
  cout << c[n - 1] << endl;
}
