#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
int main(void) {
  int n, k;
  cin >> n >> k;
  set<int> st;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      st.insert(j);
    }
  }
  vector<long long> ps(n, 0);
  ps[0] = 1;
  for (int i = 1; i < n; ++i) {
    for (auto s : st) {
      if (s > i) break;
      ps[i] += ps[i - s];
      ps[i] %= MOD;
    }
  }
  cout << ps[n - 1] << endl;
  return 0;
}
