#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  int sub[n];
  sub[0] = 1;
  for (int i = 1; i < n; i++) {
    sub[i] = 0;
  }
  vector<int> s;
  int a = 0;
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      s.push_back(j);
      a++;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a; j++) {
      if (s[j] + i <= n) {
        sub[i + s[j]] += sub[i];
        if (sub[i + s[j]] > 998244353) {
          sub[i + s[j]] -= 998244353;
        }
      }
    }
  }
  cout << sub[n - 1];
  return 0;
}
