#include <bits/stdc++.h>
using namespace std;
constexpr auto mod = 998244353;
vector<pair<int, int>> p;
bool sieve[200000 + 5];
vector<int> step;
int dp[200000 + 5];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      if (!sieve[j]) {
        step.push_back(j);
        sieve[j] = true;
      }
    }
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < step.size(); j++) {
      if (i - step[j] > 0) {
        dp[i] = (dp[i] + dp[i - step[j]]) % mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}
