#include <bits/stdc++.h>
using namespace std;
const long long losn = 1e6 + 5;
const long long maxn = 1e5 + 5;
const long long minn = 1e3 + 5;
const long long tiny = 1e2 + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long hmod = 4698571;
long long u[11], v[11];
long long tot = 0;
long long mods = 998244353;
long long tree[maxn * 2 * 4];
long long push_up(long long rt) {
  tree[rt] = tree[rt << 1] + tree[rt << 1 | 1];
  tree[rt] %= mods;
}
void build(long long l, long long r, long long rt) {
  if (l == r) {
    return;
  }
  long long mid = (l + r) >> 1;
  if (l <= mid) {
    build(l, mid, rt << 1);
  }
  if (r > mid) {
    build(mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}
long long query(long long a, long long b, long long l, long long r,
                long long rt) {
  if (a <= l && r <= b) {
    return tree[rt] % mods;
  }
  long long mid = (l + r) >> 1;
  long long sums = 0;
  if (a <= mid) {
    sums += query(a, b, l, mid, rt << 1);
  }
  if (b > mid) {
    sums += query(a, b, mid + 1, r, rt << 1 | 1);
  }
  sums %= mods;
  push_up(rt);
  return sums;
}
void update(long long x, long long sums, long long l, long long r,
            long long rt) {
  if (l == r) {
    tree[rt] = sums;
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid) {
    update(x, sums, l, mid, rt << 1);
  } else {
    update(x, sums, mid + 1, r, rt << 1 | 1);
  }
  push_up(rt);
}
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= k; i++) {
    cin >> u[i] >> v[i];
  }
  update(1, 1, 1, n, 1);
  for (long long i = 2; i <= n; i++) {
    long long sums = 0;
    for (long long j = 1; j <= k; j++) {
      if (u[j] >= i) continue;
      long long a = i - u[j], b = max((long long)1, i - v[j]);
      sums += query(b, a, 1, n, 1);
    }
    update(i, sums, 1, n, 1);
  }
  cout << query(n, n, 1, n, 1) % mods << endl;
  return 0;
}
