#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
class SegmentTree {
 private:
  int n;
  vector<long long> node, lazy;

 public:
  SegmentTree(int N) {
    n = 1;
    while (n < N) n *= 2;
    node.resize(2 * n - 1, 0);
    lazy.resize(2 * n - 1, 0);
  }
  void update(int i, int l, int r) {
    node[i] += lazy[i];
    node[i] %= mod;
    if (r - l > 1) {
      lazy[2 * i + 1] += lazy[i] / 2;
      lazy[2 * i + 2] += lazy[i] / 2;
      lazy[2 * i + 1] %= mod;
      lazy[2 * i + 2] %= mod;
    }
    lazy[i] = 0;
  }
  void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    update(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += ((r - l) * (x));
      update(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] + node[2 * k + 2]) % mod;
    }
  }
  long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    update(k, l, r);
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return node[k] % mod;
    long long sum_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
    long long sum_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return (sum_l + sum_r) % mod;
  }
  void disp() {
    for (int i : node) {
      cout << i << " ";
    }
    cout << "\n";
  }
};
int main() {
  int N, K;
  cin >> N >> K;
  int L[K], R[K];
  for (int i = 0; i < K; i++) {
    cin >> L[i] >> R[i];
  }
  SegmentTree st(N + 1);
  st.add(1, 2, 1);
  for (int i = 1; i < N; i++) {
    long long x = st.query(i, i + 1);
    for (int j = 0; j < K; j++) {
      int l = i + L[j];
      int r = i + R[j] + 1;
      st.add(l, r, x);
    }
  }
  cout << st.query(N, N + 1) << "\n";
  return 0;
}
