#include <bits/stdc++.h>
using namespace std;
long long int tree[200005] = {0};
long long int lazy[200005] = {0};
void updateRangeUtil(long long int si, long long int ss, long long int se,
                     long long int us, long long int ue, long long int diff) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= 998244353;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= 998244353;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= 998244353;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > ue || se < us) return;
  if (ss >= us && se <= ue) {
    tree[si] += (se - ss + 1) * diff;
    tree[si] %= 998244353;
    if (ss != se) {
      lazy[si * 2 + 1] += diff;
      lazy[si * 2 + 1] %= 998244353;
      lazy[si * 2 + 2] += diff;
      lazy[si * 2 + 2] %= 998244353;
    }
    return;
  }
  long long int mid = (ss + se) / 2;
  updateRangeUtil(si * 2 + 1, ss, mid, us, ue, diff);
  updateRangeUtil(si * 2 + 2, mid + 1, se, us, ue, diff);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
  tree[si] %= 998244353;
}
void updateRange(long long int n, long long int us, long long int ue,
                 long long int diff) {
  updateRangeUtil(0, 0, n - 1, us, ue, diff);
}
long long int getSumUtil(long long int ss, long long int se, long long int qs,
                         long long int qe, long long int si) {
  if (lazy[si] != 0) {
    tree[si] += (se - ss + 1) * lazy[si];
    tree[si] %= 998244353;
    if (ss != se) {
      lazy[si * 2 + 1] += lazy[si];
      lazy[si * 2 + 1] %= 998244353;
      lazy[si * 2 + 2] += lazy[si];
      lazy[si * 2 + 2] %= 998244353;
    }
    lazy[si] = 0;
  }
  if (ss > se || ss > qe || se < qs) return 0;
  if (ss >= qs && se <= qe) return tree[si];
  long long int mid = (ss + se) / 2;
  long long int mkp = getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
                      getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
  mkp %= 998244353;
  return mkp;
}
long long int getSum(long long int n, long long int qs, long long int qe) {
  if (qs < 0 || qe > n - 1 || qs > qe) {
    exit(78);
  }
  return getSumUtil(0, n - 1, qs, qe, 0);
}
void constructSTUtil(long long int arr[], long long int ss, long long int se,
                     long long int si) {
  if (ss > se) return;
  if (ss == se) {
    tree[si] = arr[ss];
    return;
  }
  long long int mid = (ss + se) / 2;
  constructSTUtil(arr, ss, mid, si * 2 + 1);
  constructSTUtil(arr, mid + 1, se, si * 2 + 2);
  tree[si] = tree[si * 2 + 1] + tree[si * 2 + 2];
}
void constructST(long long int arr[], long long int n) {
  constructSTUtil(arr, 0, n - 1, 0);
}
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n + 10];
  for (int i = 0; i < n + 5; i++) arr[i] = 0;
  arr[0] = 1;
  constructST(arr, n);
  vector<pair<long long int, long long int>> ami(k);
  for (auto &a : ami) {
    cin >> a.first;
    cin >> a.second;
  }
  for (int i = 0; i < n; i++) {
    for (auto a : ami) {
      if (i + a.first >= n) continue;
      updateRange(n, i + a.first, min(i + a.second, n - 1), getSum(n, i, i));
    }
  }
  cout << getSum(n, n - 1, n - 1) << endl;
}
