#include <bits/stdc++.h>
using namespace std;
long long get() {
  char c = getchar();
  long long x = 0LL;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x *= 10LL;
    x += (c - '0');
    c = getchar();
  }
  return x;
}
string i_t_s(int x) {
  string t = "";
  while (x) {
    t += x % 10 + '0';
    x /= 10;
  }
  reverse(t.begin(), t.end());
  return t;
}
int s_t_i(string t) {
  int x = 0;
  for (int i = 0; i < t.size(); i++) {
    x = x * 10 + (t[i] - '0');
  }
  return x;
}
int n;
int k;
bool f[200001];
long long dp[200001];
vector<int> v;
long long dfs(int x) {
  if (dp[x] != 1e10) return dp[x] % 998244353;
  dp[x] = 0;
  for (int i = 0; i < v.size(); i++) {
    if (x < v[i]) break;
    dp[x] += dfs(x - v[i]);
    dp[x] %= 998244353;
  }
  return dp[x];
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i < r + 1; i++) f[i] = true;
  }
  v.clear();
  for (int i = 1; i < n + 1; i++)
    if (f[i]) v.push_back(i);
  for (int i = 0; i < n + 1; i++) dp[i] = 1e10;
  dp[0] = 1;
  dfs(n - 1);
  cout << dp[n - 1];
  return 0;
}
