#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < (((int)(v).size())); ++i) {
    if (i) os << ", ";
    os << v[i];
  }
  return os << "]";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << "(" << p.first << " " << p.second << ")";
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
const ll MOD = 998244353;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;
template <typename T>
struct BIT {
  vector<T> bit;
  int sz;
  BIT(int n) : sz(n + 1), bit(n + 1) {}
  void add(int i, T x) {
    i += 1;
    while (i < sz) {
      (bit[i] += x) % MOD;
      i += i & -i;
    }
  }
  T sum(int i) {
    i += 1;
    T s = 0;
    while (i > 0) {
      (s += bit[i]) % MOD;
      i -= i & -i;
    }
    return s;
  }
};
template <typename T>
struct RangeAdd {
  BIT<T> bit1, bit2;
  RangeAdd(int n) : bit1(BIT<T>(n + 1)), bit2(BIT<T>(n + 1)) {}
  void add(int l, int r, T val) {
    bit1.add(l, (MOD - l * val % MOD) % MOD);
    bit1.add(r, r * val % MOD);
    bit2.add(l, val % MOD);
    bit2.add(r, (MOD - val) % MOD);
  }
  T sum(int idx) { return (bit1.sum(idx) + idx * bit2.sum(idx) % MOD) % MOD; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, k;
  cin >> n >> k;
  RangeAdd<ll> bit(n + 1);
  bit.add(0, 1, 1);
  vector<bool> v(n);
  for (int i = 0; i < (k); ++i) {
    int l, r;
    cin >> l >> r;
    r++;
    for (int j = (l); j < (r); ++j) {
      v[j] = true;
    }
  }
  vector<P> kukan;
  int nowl = -1, nowr = -1;
  for (int i = 0; i < (n); ++i) {
    if (v[i]) {
      if (nowl == -1) {
        nowl = i;
        nowr = i + 1;
      } else {
        nowr++;
      }
    } else {
      if (nowl != -1) {
        kukan.push_back({nowl, nowr});
        nowl = -1;
        nowr = -1;
      }
    }
  }
  if (nowl != -1) {
    kukan.push_back({nowl, nowr});
  }
  for (int i = 0; i < (n - 1); ++i) {
    ll val = 1;
    if (i != 0) val = (bit.sum(i + 1) - bit.sum(i) + MOD) % MOD;
    for (int j = 0; j < (((int)(kukan).size())); ++j) {
      if (i + kukan[j].first < n) {
        bit.add(i + kukan[j].first, min(n, i + kukan[j].second), val);
      }
    }
  }
  cout << (bit.sum(n) - bit.sum(n - 1) + MOD) % MOD << endl;
  return 0;
}
