#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD{998244353};
const int MAXN{200000};
vector<pair<int, int>> segments;
vector<ll> dp(MAXN + 1, 0);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  segments.reserve(K);
  for (int i{0}; i < K; ++i) {
    int l, r;
    cin >> l >> r;
    segments.emplace_back(l, r);
  }
  ll acc{1};
  for (int i{1}; i < N; ++i) {
    acc += dp[i] % MOD;
    if (acc > 0) {
      for (auto [sl, sr] : segments) {
        if (i + sl <= N) {
          dp[i + sl] += acc % MOD;
        }
        if (i + sr + 1 <= N) {
          dp[i + sr + 1] -= acc % MOD;
        }
      }
    }
  }
  cout << dp[N] << endl;
  return EXIT_SUCCESS;
}
