#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int path[n];
  memset(path, 0, sizeof(path));
  unordered_set<int> s;
  while (k--) {
    long long int l, r;
    cin >> l >> r;
    for (long long int i = l; i <= r; ++i) {
      s.insert(i);
    }
  }
  path[0] = 1;
  for (long long int i = 0; i < n; ++i) {
    if (path[i]) {
      for (auto el : s) {
        if (i + el < n) {
          path[i + el] += path[i];
          path[i + el] %= 998244353;
        }
      }
    }
  }
  cout << path[n - 1] << endl;
  return 0;
}
