#include <bits/stdc++.h>
using namespace std;
int main() {
  int32_t N, K;
  cin >> N >> K;
  vector<pair<int32_t, int32_t>> lrs(K);
  for (int32_t k = 0; k < K; ++k) {
    cin >> lrs[k].first >> lrs[k].second;
  }
  vector<uint32_t> dp{1};
  vector<uint32_t> hs(K);
  for (int32_t i = 1; i < N; ++i) {
    dp.push_back(0);
    uint32_t &cdp = dp[i];
    for (int32_t k = 0; k < K; ++k) {
      const auto &lr = lrs[k];
      auto &h = hs[k];
      int32_t e = i - lr.first;
      int32_t s = i - lr.second;
      if (e < 0) {
        continue;
      }
      h += dp[e];
      if (s > 0) {
        h -= dp[s - 1];
      }
      cdp = (cdp + h) % 998244353;
    }
  }
  cout << dp[N - 1];
}
