#include <bits/stdc++.h>
using namespace std;
long long ff[200100];
int x[200100], y[200100];
unsigned long long n, m, ans[100010 << 2], tag[100010 << 2];
inline long long ls(long long x) { return x << 1; }
inline long long rs(long long x) { return x << 1 | 1; }
inline void push_up(long long p) { ans[p] = ans[ls(p)] + ans[rs(p)]; }
void build(long long p, long long l, long long r) {
  tag[p] = 0;
  if (l == r) {
    ans[p] = ff[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
  push_up(p);
}
inline void f(long long p, long long l, long long r, long long k) {
  tag[p] = (tag[p] + k) % 998244353;
  ans[p] = ans[p] % 998244353 + k % 998244353 * (r - l + 1) % 998244353;
}
inline void push_down(long long p, long long l, long long r) {
  long long mid = (l + r) >> 1;
  f(ls(p), l, mid, tag[p]);
  f(rs(p), mid + 1, r, tag[p]);
  tag[p] = 0;
}
inline void update(long long nl, long long nr, long long l, long long r,
                   long long p, long long k) {
  if (nl <= l && r <= nr) {
    ans[p] += (k * (r - l + 1) % 998244353);
    tag[p] += k % 998244353;
    return;
  }
  push_down(p, l, r);
  long long mid = (l + r) >> 1;
  if (nl <= mid) update(nl, nr, l, mid, ls(p), k);
  if (nr > mid) update(nl, nr, mid + 1, r, rs(p), k);
  push_up(p);
}
long long query(long long q_x, long long q_y, long long l, long long r,
                long long p) {
  if (q_x + q_y == 0) return 0;
  long long res = 0;
  if (q_x <= l && r <= q_y) return ans[p];
  long long mid = (l + r) >> 1;
  push_down(p, l, r);
  if (q_x <= mid) res += query(q_x, q_y, l, mid, ls(p));
  if (q_y > mid) res += query(q_x, q_y, mid + 1, r, rs(p));
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  memset(ff, 0, sizeof ff);
  ff[1] = 1;
  ff[0] = 0;
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int p, q;
    cin >> p >> q;
    x[i] = p, y[i] = q;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long g = max(0, i - x[j]), yy = max(0, i - y[j]);
      long long ans = (query(yy, g, 1, n, 1)) % 998244353;
      update(i, i, 1, n, 1, ans);
    }
  }
  cout << (query(n, n, 1, n, 1) % 998244353);
  return 0;
}
