#include <bits/stdc++.h>
const int factor_N = 10000005;
const int tree_arr_N = 1000005;
using namespace std;
int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return x * f;
}
const int mod = 998244353;
int n, k, l, r;
unordered_map<int, bool> mp;
int main() {
  n = read();
  k = read();
  vector<int> dp(n + 1, 0), a;
  while (k--) {
    l = read();
    r = read();
    while (l <= r) {
      if (mp[l] != true) a.push_back(l), mp[l] = true;
      l++;
    }
  }
  sort(a.begin(), a.end());
  dp[1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (auto step : a) {
      if (step >= i) break;
      dp[i] = (dp[i] + dp[i - step]) % mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
