#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v, tmp;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    tmp.push_back({x, y});
  }
  sort(tmp.begin(), tmp.end());
  int px = 0, py = 0;
  for (auto g : tmp) {
    if (g.first <= py) {
      py = g.second;
    } else {
      if (px != 0 && py != 0) v.push_back({px, py});
      px = g.first;
      py = g.second;
    }
  }
  v.push_back({px, py});
  vector<int> A(n + 1);
  A[1] = 1;
  A[2] = -1;
  for (int i = 1; i <= n; i++) {
    A[i] += A[i - 1];
    if (A[i] >= 998244353) A[i] -= 998244353;
    for (auto g : v) {
      A[i + g.first] += A[i];
      if (A[i] >= 998244353) A[i] -= 998244353;
      A[i + g.second + 1] -= A[i];
      if (A[i] < 0) A[i] += 998244353;
    }
  }
  cout << A[n];
}
