#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 998244353;
int main() {
  ll n, k;
  cin >> n >> k;
  set<ll> st;
  for (int i = 0; i < k; ++i) {
    ll l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      st.insert(j);
    }
  }
  vector<ll> dp(n + 10, 0);
  dp[1] = 1;
  for (int i = 2; i < dp.size(); ++i) {
    for (const auto& e : st) {
      if (i - e < 0) break;
      dp[i] += dp[i - e];
      dp[i] %= mod;
    }
  }
  cout << dp[n] << endl;
}
