#include <bits/stdc++.h>
using namespace std;
long long dp[200001];
int main() {
  int n = 0, k, seg[200001] = {0};
  cin >> n >> k;
  vector<int> S;
  for (int i = 0; i < k; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j <= R; j++) seg[L] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (seg[i] == 1) S.push_back(i);
  }
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j : S) {
      if (i - j >= 0) dp[i] = (dp[i] + dp[i - j]) % 998244353;
    }
  }
  cout << dp[n];
  return 0;
}
