#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    if (i != v.size() - 1) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << "[";
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << "(";
  os << v.first << ", " << v.second << ")";
  return os;
}
void go() { cin.tie(nullptr)->sync_with_stdio(false); }
const long long mod = 998244353, N = 2e5 + 5;
long long n, k;
vector<long long> poss, dp(N);
long long solve(long long idx) {
  if (idx == n) return 1;
  if (idx > n) return 0;
  long long& ans = dp[idx];
  if (~ans) return ans;
  long long res = 0;
  for (long long i = 0; i < poss.size(); i++) {
    if (idx + poss[i] > n) break;
    res += solve(idx + poss[i]);
    res %= mod;
  }
  return ans = res;
}
int32_t main() {
  cin >> n >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    for (long long i = x; i <= y; i++) {
      poss.push_back(i);
    }
  }
  for (long long i = 0; i < n + 2; i++) {
    dp[i] = -1;
  }
  sort(poss.begin(), poss.end());
  cout << solve(1);
}
