#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 998244353;
ll dp[200005];
int main() {
  int n, k;
  cin >> n >> k;
  vector<P> ran(k);
  for (int i = 0; i < (int)(k); ++i) cin >> ran[i].first >> ran[i].second;
  dp[0] = 1;
  priority_queue<pair<P, ll>> pq;
  for (int i = 0; i < (int)(n); ++i) {
    vector<pair<P, ll>> v;
    while (!pq.empty()) {
      auto t = pq.top();
      pq.pop();
      int l = -t.first.first;
      int r = -t.first.second;
      if (i <= r) v.push_back(t);
      if (i < l)
        break;
      else if (l <= i && i <= r)
        (dp[i] += t.second) %= mod;
    }
    for (auto t : v) pq.push(t);
    if (dp[i] == 0) continue;
    for (int j = 0; j < (int)(k); ++j) {
      int l = ran[j].first;
      int r = ran[j].second;
      pq.push({{-(l + i), -(r + i)}, dp[i]});
    }
  }
  cout << dp[n - 1] % mod << endl;
  return 0;
}
