#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
  std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1;
  ZZ(comma, args...);
}
long long MOD = 998244353;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k), 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> ans(n + 1, 0);
  ans[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    for (int j = 0; j < s.size(); j++) {
      if (i - s[j] >= 1) {
        ans[i] = (ans[i] + ans[i - s[j]]) % MOD;
        ans[i] %= MOD;
      }
    }
  }
  cout << ans[n];
}
int main() {
  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
