#include <bits/stdc++.h>
using namespace std;
long long n, k, l, r, m = 998244353, dp[200005], sum[200005];
vector<int> v;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> l >> r;
    sum[l]++;
    sum[r + 1]--;
  }
  for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];
  for (int i = 1; i <= n; i++) {
    if (sum[i]) v.push_back(i);
  }
  dp[1] = 1LL;
  for (int i = 2; i <= n; i++) {
    for (auto j : v) {
      if (i - j >= 1) {
        dp[i] += dp[i - j];
        dp[i] %= m;
      }
    }
  }
  cout << dp[n];
  return 0;
}
