#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long mod = 998244353;
  long long dp[n + 1];
  for (long long i = 0; i <= n; i++) dp[i] = 0;
  dp[1] = 1;
  bool flag[n + 1];
  for (long long i = 0; i <= n; i++) flag[i] = false;
  for (long long i = 0; i < k; i++) {
    long long r, l;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      flag[j] = true;
    }
  }
  vector<long long> vec;
  for (long long i = 1; i < n; i++) {
    if (flag[i]) vec.push_back(i);
  }
  for (long long i = 1; i < n; i++) {
    if (dp[i] == 0) continue;
    for (auto p : vec) {
      long long j = i + p;
      if (j <= n) {
        dp[j] += dp[i];
        dp[j] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
