#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  const int mod = 998244353;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  int dp[N + 1];
  dp[0] = 0;
  dp[1] = 1;
  for (int a = 2; a <= N; a++) {
    dp[a] = 0;
  }
  int LR[K + 1][3];
  bool TF[N + 1];
  for (int i = 0; i <= N; i++) {
    TF[i] = false;
  }
  for (int i = 1; i <= K; i++) {
    cin >> LR[i][1] >> LR[i][2];
    for (int j = LR[i][1]; j <= LR[i][2]; j++) {
      TF[j] = true;
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < i; j++) {
      if (TF[i - j] == true) {
        dp[i] += dp[j];
      }
      dp[i] = dp[i] % mod;
    }
  }
  cout << dp[N] << endl;
  return 0;
}
