#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> range(K);
  for (int i = 0; i < K; i++) cin >> range[i].first >> range[i].second;
  const int MOD = 998244353;
  sort(range.begin(), range.end());
  vector<int> S;
  for (int i = 0; i < K; i++) {
    for (int j = range[i].first; j <= range[i].second; j++) {
      if (S.empty() || S.back() != j) S.push_back(j);
    }
  }
  vector<int> dp(N + 1);
  dp[1] = 1;
  for (int i = S[0] + 1; i <= N; i++) {
    for (int j : S) {
      if (j >= i) break;
      dp[i] = (dp[i] + dp[i - j]) % MOD;
    }
  }
  cout << dp[N];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  cout << '\n';
  return 0;
}
