#include <bits/stdc++.h>
template <typename T>
void view(T e) {
  std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v) {
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv) {
  for (const auto& v : vv) {
    view(v);
  }
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
struct LazySegmentTree {
 private:
  int n;
  vector<ll> node, lazy;

 public:
  LazySegmentTree(vector<ll> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      node[k] = (node[k] + lazy[k]) % 998244353;
      if (r - l > 1) {
        lazy[2 * k + 1] = (lazy[2 * k + 1] + lazy[k] / 2) % 998244353;
        lazy[2 * k + 2] = (lazy[2 * k + 2] + lazy[k] / 2) % 998244353;
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = (lazy[k] + (r - l) * x) % 998244353;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = (node[2 * k + 1] + node[2 * k + 2]) % 998244353;
    }
  }
  ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return node[k];
    ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return (vl + vr) % 998244353;
  }
};
void Main() {
  int N, K;
  cin >> N >> K;
  vi L(K), R(K);
  for (int i = (0); i < (K); ++i) cin >> L[i] >> R[i];
  LazySegmentTree seg(vector<ll>(N, 0));
  seg.add(0, 1, 1);
  for (int i = (0); i < (N); ++i) {
    for (int j = (0); j < (K); ++j) {
      seg.add(L[j] + i, R[j] + i + 1, seg.getsum(i, i + 1));
    }
  }
  cout << seg.getsum(N - 1, N) << endl;
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
