#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr long long INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr long double eps = 1e-12;
constexpr long double pi = 3.141592653589793238;
constexpr long long ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
void fail() {
  cout << "-1\n";
  exit(0);
}
void no() {
  cout << "No\n";
  exit(0);
}
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
istream &operator>>(istream &s, vector<T> &v) {
  for (auto &e : v) s >> e;
  return s;
}
template <class T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  for (auto &e : v) s << e << ' ';
  return s;
}
struct fastio {
  fastio() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);
  }
} fastio_;
constexpr long long mod = mod998;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> dp(n + 1), sum(n + 2);
  vector<int> l(k), r(k);
  for (long long i = 0; i < (k); i++) cin >> l[i] >> r[i];
  dp[1] = sum[2] = 1;
  for (int i = 2; i <= n; i++) {
    for (long long j = 0; j < (k); j++) {
      int x = i - l[j] + 1;
      int y = i - r[j];
      if (x >= 0) dp[i] += sum[x];
      if (y >= 0) dp[i] -= sum[y];
    }
    if (dp[i] >= mod) dp[i] -= mod;
    if (dp[i] < 0) dp[i] += mod;
    sum[i + 1] = sum[i] + dp[i];
    if (sum[i + 1] >= mod) sum[i + 1] -= mod;
  }
  cout << dp[n] << '\n';
}
