#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  out << "[";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator<<(ostream& out, const set<T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& v : a) {
    out << (first ? "" : ", ");
    out << v;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator<<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{";
  bool first = true;
  for (auto& p : a) {
    out << (first ? "" : ", ");
    out << p.first << ":" << p.second;
    first = 0;
  }
  out << "}";
  return out;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
using ll = long long;
using P = pair<long long, long long>;
const long long mod = 998244353;
void add(long long& a, long long b) {
  a = (a + b) % mod;
  a = (a % mod + mod) % mod;
}
signed main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> l(k), r(k);
  for (long long i = 0; i < (k); i++) cin >> l[i] >> r[i];
  vector<long long> dp(n + 3);
  dp[1] = 1;
  add(dp[2], -1);
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    add(sum, dp[i]);
    for (long long j = 0; j < (k); j++) {
      add(dp[r[j] + 1 + i], -sum);
      add(dp[l[j] + i], sum);
    }
  }
  for (long long i = 1; i <= n; i++) add(dp[i + 1], dp[i]);
  cout << dp[n] << endl;
  return 0;
}
