#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<pair<int, int>> corners;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    corners.push_back(pair<int, int>(l, r));
  }
  sort(corners.begin(), corners.end());
  long CON = 998244353;
  array<long, 2 * 100000 + 1> dp;
  dp[1] = 1;
  for (int i = 1; i <= n; i++) {
    for (auto &corner : corners) {
      if (i + corner.first > n) {
        break;
      }
      for (int j = corner.first; j <= corner.second; ++j) {
        if (i + j > n) {
          break;
        }
        dp[i + j] += dp[i];
        dp[i + j] %= CON;
      }
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  solve();
}
