#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 5;
long long mod = 998244353;
long long a[mx], ts[mx * 4], lz[mx * 4];
long long minx(long long dsa, long long dsb) {
  if (dsa > dsb)
    return dsb;
  else
    return dsa;
}
void lazy(long long node, long long start, long long end) {
  if (start != end) {
    lz[2 * node] += lz[node];
    lz[2 * node + 1] += lz[node];
  }
  ts[node] += (lz[node] * (end - start + 1)) % mod;
  ts[node] = ts[node] % mod;
  lz[node] = 0;
}
void build(long long n, long long l, long long r) {
  if (l == r) {
    ts[n] = a[l];
    return;
  } else if (l > r)
    return;
  long long mid = (l + r) / 2;
  build(n * 2, l, mid);
  build(n * 2 + 1, mid + 1, r);
  ts[n] = ts[n * 2] + ts[n * 2 + 1];
}
long long sum(long long v, long long l, long long r, long long ll,
              long long rr) {
  lazy(v, l, r);
  if (rr < l or ll > r) return 0;
  if (ll <= l and rr >= r) return (ts[v]) % mod;
  long long mid = (l + r) / 2;
  return (sum(v * 2, l, mid, ll, rr) + sum(v * 2 + 1, mid + 1, r, ll, rr)) %
         mod;
}
void update(long long v, long long l, long long r, long long ll, long long rr,
            long long val) {
  lazy(v, l, r);
  if (rr < l or ll > r) return;
  if (ll <= l and rr >= r) {
    lz[v] = val % mod;
    lazy(v, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  update(v * 2, l, mid, ll, rr, val);
  update(v * 2 + 1, mid + 1, r, ll, rr, val);
  ts[v] = (ts[v * 2] + ts[v * 2 + 1]) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < k; ++i) {
    long long am, ak;
    cin >> am >> ak;
    v.push_back(make_pair(am, ak));
  }
  sort(v.begin(), v.end());
  a[1] = 1;
  build(1, 1, n);
  for (long long i = 1; i < n; ++i) {
    long long say = sum(1, 1, n, i, i);
    if (say == 0) continue;
    for (long long jk = 0; jk < k; ++jk) {
      if (v[jk].first + i > n) break;
      update(1, 1, n, v[jk].first + i, minx(v[jk].second + i, n), say);
    }
  }
  cout << (sum(1, 1, n, n, n)) % mod << '\n';
}
