#include <bits/stdc++.h>
using namespace std;
const int IINF = 1e9;
const long long LINF = 1e18;
const long long MOD = 998244353;
template <typename T = int, typename E = T>
class SegmentTree {
 private:
  int N;
  vector<pair<int, int>> domains;
  vector<T> values;
  T e;
  function<T(T, T)> merge;
  function<T(T, T)> apply;
  int init(int l, int r, int i = 1) {
    domains[i] = make_pair(l, r);
    if (r - l == 1) {
      return values[i];
    }
    int mid = (l + r) / 2;
    return values[i] = merge(init(l, mid, i * 2), init(mid, r, i * 2 + 1));
  }

 public:
  SegmentTree(vector<T> v, function<T(T, T)> merge, T e,
              function<T(T, E)> apply) {
    int n = v.size();
    N = 1;
    for (; N < n; N *= 2)
      ;
    domains.resize(2 * N);
    values.resize(2 * N);
    for (int i = 0; i < (int)(n); i++) {
      values[i + N] = v[i];
    }
    for (int i = (n); i < (N); ++i) {
      values[i + N] = e;
    }
    this->merge = merge;
    this->apply = apply;
    init(0, N);
  }
  SegmentTree(vector<T> v, function<T(T, T)> merge, T e)
      : SegmentTree(v, merge, e, [](T x, E y) { return y; }) {}
  SegmentTree(vector<T> v)
      : SegmentTree(
            v, [](T x, T y) { return x + y; }, 0) {}
  SegmentTree(int n) : SegmentTree(vector<T>(n, 0)) {}
  void update(int index, E x) {
    int i = index + N;
    values[i] = apply(values[i], x);
    i /= 2;
    for (; 1 <= i; i /= 2) {
      values[i] = merge(values[i * 2], values[i * 2 + 1]);
    }
  }
  int segment(int l, int r) {
    if (l == r) {
      return 0;
    }
    assert(l <= r);
    int left, right;
    left = l + N;
    right = r + N - 1;
    T res = e;
    for (; left != right;) {
      if (left % 2 == 1) {
        res = merge(res, values[left]);
        left++;
        l++;
      } else if (right % 2 == 0) {
        res = merge(res, values[right]);
        right--;
        r--;
      } else {
        left /= 2;
        right /= 2;
      }
    }
    if (l < r) {
      res = merge(res, values[left]);
    }
    return res;
  }
};
int main() {
  int N, K;
  cin >> N >> K;
  vector<long long> L(K), R(K);
  for (int i = 0; i < (int)(K); i++) {
    cin >> L[i] >> R[i];
  }
  vector<long long> v(N + 1, 0);
  v[1] = 1;
  SegmentTree<long long> tree(
      v, [](long long x, long long y) { return (x + y) % 998244353; }, 0,
      [](long long x, long long y) { return (x + y) % 998244353; });
  for (int i = (2); i < (N + 1); ++i) {
    for (int j = 0; j < (int)(K); j++) {
      int l = max<long long>(1, i - R[j]);
      int r = i - L[j] + 1;
      if (r <= 1) continue;
      long long seg = tree.segment(l, r);
      tree.update(i, seg);
    }
  }
  cout << tree.segment(N, N + 1) << endl;
  return 0;
}
