#include <bits/stdc++.h>
using namespace std;
struct MyHash {
  std::size_t operator()(pair<long, long> const &p) const noexcept {
    std::size_t h1 = std::hash<long>{}(p.first);
    std::size_t h2 = std::hash<long>{}(p.second);
    return h1 ^ (h2 << 1);
  }
};
struct MyComp {
  template <typename T>
  std::size_t operator()(T &l, T &r) const noexcept {
    return l < r;
  }
};
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (auto i = 0; i < (k); i++) {
    cin >> l[i] >> r[i];
  }
  vector<long long> dp(n + 1), dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  long CON = 998244353;
  for (int i = 2; i <= n; i++) {
    for (auto j = 0; j < (k); j++) {
      int idx_r = i - l[j];
      int idx_l = i - r[j];
      if (idx_r < 1) {
        continue;
      }
      idx_l = max(1, idx_l);
      dp[i] += (dpsum[idx_r] - dpsum[idx_l - 1]);
      dp[i] %= CON;
    }
    dpsum[i] = (dpsum[i - 1] + dp[i]) % CON;
  }
  cout << (dp[n] > 0 ? dp[n] : dp[n] + CON) << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
}
