#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll mod = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N + 2);
  for (int i = 0; i < (K); i++) {
    int l, r;
    cin >> l >> r;
    p[l] += 1;
    p[r + 1] -= 1;
  }
  vector<int> S;
  for (int i = 1; i <= N; i++) {
    p[i] += p[i - 1];
    if (p[i] > 0) S.push_back(i);
  }
  vector<ll> dp(2 * N + 5);
  dp[0] = 1;
  for (int i = 0; i < (N); i++) {
    for (int j : S) {
      dp[i + j] += dp[i];
      dp[i + j] %= mod;
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
