#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<bool> h(n + 1, false);
  vector<int> v;
  vector<long long> dp(n + 1, 0);
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) h[j] = true;
  }
  for (int i = 0; i < n + 1; i++)
    if (h[i]) v.push_back(i);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < v.size(); j++)
      if (i - v[j] >= 0) dp[i] += dp[i - v[j]], dp[i] = dp[i] % mod;
  }
  cout << dp[n] << '\n';
  return 0;
}
