#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll p = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> TF(N + 4, false);
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      TF[j] = true;
    }
  }
  vector<ll> dp(N + 4, 0);
  dp[N] = 1;
  for (int i = N - 1; i >= 1; i--) {
    int rest = N - i;
    for (int j = 1; j <= rest; j++) {
      if (TF[j]) {
        dp[i] += dp[i + j] % p;
      }
    }
  }
  cout << dp[1] << endl;
  return 0;
}
