#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int cmod = 998244353;
const long long int N = 3e5 + 5;
const long long int inf = 1e18 + 2;
void solve(long long int Case) {
  long long int n, k;
  cin >> n >> k;
  set<long long int> s;
  while (k--) {
    long long int a, b;
    cin >> a >> b;
    for (long long int i = a; i <= b; i++) s.insert(i);
  }
  vector<pair<long long int, long long int>> seg;
  long long int prev = -1, l = 0, r = 0;
  for (auto x : s) {
    if (prev == -1) {
      l = r = x;
      prev = x;
      continue;
    }
    if (x == prev + 1)
      r++;
    else {
      seg.push_back({l, r});
      prev = x;
      l = r = x;
    }
  }
  if (l != 0) seg.push_back({l, r});
  long long int ad[n + 10], dp[n + 10];
  memset(ad, 0, sizeof ad);
  memset(dp, 0, sizeof dp);
  dp[1] = 1;
  for (long long int i = 1; i <= n; i++) {
    ad[i] = (ad[i] + ad[i - 1]) % cmod;
    dp[i] = (dp[i] + ad[i] + cmod) % cmod;
    for (long long int j = 0; j < seg.size(); j++) {
      if (i + seg[j].first > n) continue;
      ad[i + seg[j].first] = (ad[i + seg[j].first] + dp[i]) % cmod;
      long long int temp = min(i + seg[j].second, n);
      ad[temp + 1] = (ad[temp + 1] - dp[i] + cmod) % cmod;
    }
  }
  cout << dp[n] << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int testcase = 1;
  long long int Case = 1;
  while (testcase--) {
    solve(Case);
  }
  return 0;
}
