#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6 + 10, M = 2e6 + 10, mod = 998244353, inf = 0x3f3f3f;
long long v[N], dp[N];
vector<int> a;
int dfs(long long n) {
  if (~dp[n]) return dp[n];
  dp[n] = 0;
  for (auto u : a)
    if (u <= n)
      dp[n] = (dp[n] + dfs(n - u)) % mod;
    else
      break;
  return dp[n];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, k, ans = 0;
  cin >> n >> k;
  for (int i = 1; (i) <= (k); i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) v[j] = 1;
  }
  for (int i = 1; (i) <= (n); i++) {
    dp[i] = -1;
    if (v[i]) a.push_back(i);
  }
  reverse(a.begin(), a.end());
  dp[0] = 1;
  cout << dfs(n - 1) << '\n';
  return 0;
}
