#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
constexpr long long ms = 2 * 1e5 + 7;
constexpr long long mod = 998244353;
long long dp[ms];
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<int> ok(n, 0);
  vector<int> p;
  for (int i = 0; i < k; ++i) {
    int l, r;
    cin >> l >> r;
    ++ok[l];
    --ok[r + 1];
  }
  for (int i = 1; i < n; ++i) {
    ok[i] += ok[i - 1];
    if (ok[i] == 1) {
      p.push_back(i);
    }
  }
  memset(dp, -1ll, sizeof(dp));
  function<long long(int)> calc_dp = [&](int i) {
    if (i > n) return 0ll;
    if (i == n) return 1ll;
    if (dp[i] != -1ll) return dp[i];
    long long sum = 0;
    for (int d : p) {
      sum += calc_dp(i + d);
      sum %= mod;
    }
    dp[i] = sum;
    return sum;
  };
  cout << calc_dp(1) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
