#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200005;
const int mod = 998244353;
struct Seg {
  int l, r;
  bool operator<(const Seg& rhs) const { return l < rhs.l; }
} seg[11];
ll c[N];
int n, k;
int lowbit(int x) { return x & (-x); }
void add(int x, ll d) {
  for (int i = x; i <= n; i += lowbit(i)) c[i] = (c[i] + d) % mod;
}
ll query(int x) {
  ll res = 0;
  for (int i = x; i; i -= lowbit(i)) res = (res + c[i]) % mod;
  return res;
}
ll Mod(ll a) { return (a % mod + mod) % mod; }
ll Query(int q) {
  ll res = 0;
  for (int i = 1; i <= k; ++i) {
    int st = max(1, q - seg[i].r);
    int ed = q - seg[i].l;
    if (ed < 1) break;
    res = Mod(res + query(ed) - query(st - 1));
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &seg[i].l, &seg[i].r);
  }
  sort(seg + 1, seg + k + 1);
  add(1, 1);
  for (int i = 2; i <= n; ++i) {
    int now = Query(i);
    add(i, now);
  }
  printf("%lld\n", query(n) - query(n - 1));
  return 0;
}
