#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const long long N = 2e6 + 5;
const long long INF = 1e18L;
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
template <typename T, typename... Args>
inline string arrStr(T arr, long long n) {
  stringstream s;
  s << "[";
  for (long long i = 0; i < n - 1; i++) s << arr[i] << ",";
  if (n > 0) s << arr[n - 1];
  s << "]";
  return s.str();
}
inline void __trace_begin(long long line) { cerr << "#" << line << ": "; }
template <typename T>
inline void __trace_out_var(vector<T> val) {
  cerr << arrStr(val, val.size());
}
template <typename T>
inline void __trace_out_var(T* val) {
  cerr << arrStr(val, 10);
}
template <typename T>
inline void __trace_out_var(T val) {
  cerr << val;
}
inline void __trace(vector<string>::iterator it) { cerr << '\n'; }
template <typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
long long ar[N];
long long dp[N];
vector<long long> v;
inline long long add(long long x, long long y, long long mod) {
  if (y >= mod) y %= mod;
  if (x >= mod) x %= mod;
  x += y;
  return (x >= mod ? x - mod : x);
}
inline long long mul(long long x, long long y, long long mod) {
  if (x >= mod) x %= mod;
  if (y >= mod) y %= mod;
  return (x * y) % mod;
}
inline long long sub(long long x, long long y, long long mod) {
  x -= y;
  if (x + mod <= 0) {
    x %= mod;
  }
  return (x < 0 ? x + mod : x);
}
long long PowerMod(long long x, long long n, long long mod) {
  long long res = 1;
  for (; n > 0;) {
    if (n & 1) {
      res = mul(res, x, mod);
    }
    x = mul(x, x, mod);
    n /= 2;
  }
  return res;
}
inline long long div(long long a, long long b, long long mod) {
  return (mul(a, PowerMod(b, mod - 2, mod), mod));
}
long long fac[N], inv[N];
void pre() {
  fac[0] = inv[0] = 1;
  for (long long i = 1; i < N; i++)
    fac[i] = mul(fac[i - 1], i, 998244353),
    inv[i] = PowerMod(fac[i], 998244353 - 2, 998244353);
}
inline long long NCR(long long n, long long r) {
  return (
      long long)(mul(fac[n], mul(inv[r], inv[n - r], 998244353), 998244353));
}
long long mp[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  pre();
  while (T--) {
    long long n, m;
    cin >> n >> m;
    for (long long j = 0; j < m; j++) {
      long long x, y;
      cin >> x >> y;
      for (long long i = x; i <= y; i++) v.push_back(i), mp[i] = 1;
    }
    sort(v.begin(), v.end());
    long long sz = v.size();
    bool ok = 0;
    long long tot = 0;
    if (sz > 1e4) {
      ok = 1;
      tot = NCR(2 * n - 1, n - 1);
      v.clear();
      for (long long i = 1; i <= n; i++) {
        if (mp[i] == 0) v.push_back(i);
      }
    }
    for (auto i : v) {
      dp[i]++;
    }
    sz = v.size();
    for (long long j = 0; j < n; j++) {
      long long ii = upper_bound(v.begin(), v.end(), j) - v.begin();
      for (long long i = 0; i < min(sz, ii); i++) {
        if (v[i] <= j) {
          dp[j] = add(dp[j], dp[j - v[i]], 998244353);
        }
      }
    }
    long long ans = 0;
    if (ok) {
      ans = sub(tot, dp[n - 1], 998244353);
    } else
      ans = dp[n - 1];
    cout << dp[n - 1];
  }
  return 0;
}
