#include <bits/stdc++.h>
using namespace std;
using std::ios;
constexpr int MOD = 1e9 + 7;
constexpr int mod = 998244353;
template <typename T>
T power(T a, T b) {
  T r = 1;
  while (b) {
    if (b & 1) r *= a;
    b /= 2;
    a *= a;
  }
  return r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  vector<int> l(n), r(n);
  vector<int> s;
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
    for (int j = l[i]; j < r[i] + 1; j++) s.push_back(j);
  }
  sort((s).begin(), (s).end());
  vector<long long> dp(n + 1, 0);
  for (auto i : s) {
    dp[i]++;
  }
  for (int i = 1; i <= n; i++) {
    for (auto j : s) {
      if (i - j < 0) break;
      dp[i] = dp[i] + dp[i - j];
      dp[i] %= mod;
    }
  }
  cout << dp[n - 1];
}
