#include <bits/stdc++.h>
using namespace ::std;
template <class T>
istream& operator>>(istream& I, vector<T>& v) {
  for (T& e : v) I >> e;
  return I;
}
template <class T>
ostream& operator<<(ostream& O, const vector<T>& v) {
  for (const T& e : v) O << e << ' ';
  return O;
}
const int mod = 998244353;
void _main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) a.emplace_back(j);
  }
  vector<int> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto j : a) {
      if (i - j >= 0) {
        dp[i] += dp[i - j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp.back();
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int _t = 1;
  while (_t--) _main();
  return 0;
}
