#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
  cout << "\n";
}
long long powm(long long a, long long b, long long mod) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const long long mod = 998244353;
const long long N = 1000005;
const long long inf = 1e9;
long long n;
long long st[4 * N], ar[N], lazy[4 * N];
void build(int si, int ss, int second) {
  if (ss == second) {
    st[si] = ar[ss];
    return;
  }
  int mid = (ss + second) / 2;
  build(2 * si, ss, mid);
  build(2 * si + 1, mid + 1, second);
  st[si] = st[2 * si] + st[2 * si + 1];
}
int query(int si, int ss, int second, int qs, int qe) {
  if (lazy[si] != 0) {
    int dx = lazy[si];
    lazy[si] = 0;
    (st[si] += dx * (second - ss + 1)) % mod;
    if (ss != second) {
      (lazy[2 * si] += dx) % mod;
      (lazy[2 * si + 1] += dx) % mod;
    }
  }
  if (ss > qe || second < qs) return 0;
  if (ss >= qs && second <= qe) return st[si] % mod;
  int mid = (ss + second) / 2;
  return (query(2 * si, ss, mid, qs, qe) +
          query(2 * si + 1, mid + 1, second, qs, qe)) %
         mod;
}
void update(int si, int ss, int second, int qs, int qe, int val) {
  if (lazy[si] != 0) {
    int dx = lazy[si] % mod;
    lazy[si] = 0;
    (st[si] += dx * (second - ss + 1)) % mod;
    if (ss != second) {
      (lazy[2 * si] += dx) % mod;
      (lazy[2 * si + 1] += dx) % mod;
    }
  }
  if (ss > qe || second < qs) return;
  if (ss >= qs && second <= qe) {
    int dx = ((second - ss + 1) * val) % mod;
    (st[si] += dx) % mod;
    if (ss != second) {
      (lazy[2 * si] += val) % mod;
      (lazy[2 * si + 1] += val) % mod;
    }
    return;
  }
  int mid = (ss + second) / 2;
  update(2 * si, ss, mid, qs, qe, val);
  update(2 * si + 1, mid + 1, second, qs, qe, val);
  st[si] = (st[2 * si] + st[2 * si + 1]) % mod;
}
void solve() {
  int n, k;
  cin >> n >> k;
  for (long long i = 0; i < (4 * n + 1); i++) lazy[i] = 0;
  for (long long i = 0; i < (3 * n); i++) ar[i + 1] = 0;
  ar[1] = 1;
  build(1, 1, 3 * n);
  vector<pair<int, int>> pr;
  for (long long i = 0; i < (k); i++) {
    int x, y;
    cin >> x >> y;
    pr.push_back({x, y});
  }
  sort(pr.begin(), pr.end());
  for (long long i = (1); i < (n); i++) {
    for (long long j = 0; j < (k); j++) {
      update(1, 1, n, i + pr[j].first, i + pr[j].second, query(1, 1, n, i, i));
    }
  }
  cout << query(1, 1, n, n, n) % mod << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
