#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000001;
struct edge {
  int to, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};
struct pos {
  long long a;
  int b;
};
int l[11], r[11];
pair<int, int> d[11] = {};
vector<pair<int, int> > vec;
long long dp[200002] = {};
long long t[200002] = {};
long long t2[200002] = {};
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
    d[i].first = l[i];
    d[i].second = r[i];
  }
  sort(d, d + k);
  int mi = d[0].first, ma = d[0].second;
  for (int i = 0; i < k - 1; ++i) {
    if (ma < d[i + 1].first) {
      vec.push_back(make_pair(mi, ma));
      mi = d[i + 1].first;
      ma = d[i + 1].second;
      continue;
    }
    ma = max(ma, d[i + 1].second);
  }
  vec.push_back(make_pair(mi, ma));
  for (int i = 2; i < n + 1; i++) {
    long long x = 0;
    for (int j = 0; j < vec.size(); ++j) {
      if (vec[j].first >= i) break;
      if (vec[j].second >= i - 1) {
        dp[i] += t[i - vec[j].first] + 1;
      } else
        dp[i] += (t[i - vec[j].first] - t[i - vec[j].second - 1]) +
                 998244353 * (t2[i - vec[j].first] - t2[i - vec[j].second - 1]);
      x += dp[i] / 998244353;
      dp[i] %= 998244353;
    }
    t[i] += t[i - 1];
    t[i] += dp[i];
    if (t[i] + dp[i] >= 998244353) t2[i]++;
    t2[i] += t2[i - 1] + x;
    t[i] %= 998244353;
    dp[i] %= 998244353;
  }
  cout << dp[n] << endl;
  return 0;
}
