#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> s;
  for (int i = 0; i < k; ++i) {
    int l, r;
    std::cin >> l >> r;
    for (int j = l; j <= r; ++j) {
      s.push_back(j);
    }
  }
  std::sort(s.begin(), s.end());
  int x = 998244353;
  int count = 0;
  std::queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (int d : s) {
      int next = i + d;
      if (next < n) {
        q.push(next);
      } else if (next == n) {
        ++count;
      }
    }
  }
  std::cout << count % x << std::endl;
  return 0;
}
