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