#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  vector<long long> dp(2 * n + 100);
  dp[1] = 1;
  dp[2] = -1;
  for (int i = 1; i <= n; i++) {
    (dp[i] += dp[i - 1] + MOD) %= MOD;
    for (int j = 0; j < k; j++) {
      dp[i + l[j]] += dp[i];
      dp[i + r[j] + 1] -= dp[i];
    }
  }
  cout << dp[n] << "\n";
  return 0;
}
