#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 998244353;
const double EPS = 1e-9;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 62) - 1;
inline int in() {
  int x;
  cin >> x;
  return x;
}
inline ll lin() {
  ll x;
  cin >> x;
  return x;
}
inline char chin() {
  char x;
  cin >> x;
  return x;
}
inline string stin() {
  string x;
  cin >> x;
  return x;
}
inline double din() {
  double x;
  cin >> x;
  return x;
}
template <typename T>
inline ll suma(const vector<T>& a) {
  ll res(0);
  for (auto&& x : a) res += x;
  return res;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
char itoa(int n) { return n + '0'; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int dy[4] = {0, -1, 0, 1};
const int dx[4] = {1, 0, -1, 0};
ll dp[200005];
int main() {
  ll n, k;
  cin >> n >> k;
  vl s(n + 1);
  for (int i = (0); i < (k); ++i) {
    ll l, r;
    cin >> l >> r;
    l--, r--;
    s[l]++;
    s[r + 1]--;
  }
  for (int i = (0); i < (n); ++i) s[i + 1] += s[i];
  dp[0] = 1;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (s.size()); ++j) {
      if (!s[j]) continue;
      ll d = j + 1;
      if (i + d > n) continue;
      dp[i + d] += dp[i];
      dp[i + d] %= mod;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
