#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;
const ll mod = 998244353;
long long mod_pow(long long x, long long n, long long mod) {
  long long a = 1LL;
  while (n) {
    if (n % 2) a = ((a % mod) * (x % mod)) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n /= 2LL;
  }
  return a;
}
struct LazySegmentTree {
 public:
  int n;
  vector<ll> node, lazy;
  LazySegmentTree(vector<ll> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; ++i) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i)
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      node[k] += lazy[k] % mod;
      if (r - l > 1) {
        lazy[2 * k + 1] += (lazy[k] * mod_pow(2LL, mod - 2, mod)) % mod;
        lazy[2 * k + 2] += (lazy[k] * mod_pow(2LL, mod - 2, mod)) % mod;
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= a or b <= l) return;
    if (a <= l and r <= b) {
      lazy[k] += ((r - l) * x) % mod;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = (node[2 * k + 1] % mod) + (node[2 * k + 2] % mod);
      node[k] %= mod;
    }
  }
  ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a or b <= l) return 0;
    eval(k, l, r);
    if (a <= l and r <= b) return node[k] % mod;
    ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return (vl + vr) % mod;
  }
};
ll L[11], R[11];
int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> v(N + 10);
  LazySegmentTree lst(v);
  lst.add(1, 2, 1);
  for (int i = (0); (i) < (int)(K); ++(i)) {
    cin >> L[i] >> R[i];
  }
  for (int i = 1; i < N; ++i) {
    ll tmp = lst.getsum(i, i + 1);
    for (int k = 0; k < K; ++k) {
      int l = L[k] + i, r = min(R[k] + i, (ll)N);
      lst.add(l, r + 1, tmp);
    }
  }
  cout << lst.getsum(N, N + 1) << endl;
}
