#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << "(" << v.first << ", " << v.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < v.size(); i++) {
    if (i) os << ", ";
    os << v[i];
  }
  os << "}";
  return os;
}
int main() {
  ll mod = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  vector<int> r(n);
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<ll> dp(n, 0);
  vector<ll> acc(n + 1, 0);
  dp[0] = 1;
  acc[1] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] += acc[max(0, i - l[j] + 1)] - acc[max(0, i - r[j])];
      acc[i + 1] = acc[i] + dp[i];
    }
  }
  cout << dp[n - 1] % mod << endl;
  return 0;
}
