#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  vector<ll> ans(n + 10, 0);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  ans[0] = 1;
  ll now = 0;
  for (int i = 0; i < n; i++) {
    now += ans[i];
    if (now > 0) {
      for (int j = 0; j < k; j++) {
        ans[min(l[j] + i, n)] += now;
        ans[min(r[j] + i + 1, n)] -= now;
      }
    }
    if (ans[i] < 0) {
      ans[i] += MOD;
    }
    ans[i] %= MOD;
  }
  if (ans[n - 1] < 0) {
    ans[n - 1] += MOD;
  }
  cout << ans[n - 1] % MOD << endl;
  return 0;
}
