#include <bits/stdc++.h>
using namespace std;
constexpr int P = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> moves(k);
  for (pair<int, int> &p : moves) cin >> p.first >> p.second;
  vector<int> ways(2 * n+255,0);
  ways[1]=1;
  ways[2]=P-1;
  int prefsum = 0;
  for (int i = 1; i <= n; ++i) {
    (prefsum += ways[i]) %= P;
    for (auto &[l, r] : moves) {
      ways[i + l] = (ways[i + l] + prefsum) % P;
      ways[i + r + 1] = (P - prefsum + ways[i + r + 1]) % P;
    }
  }
  cout << prefsum << '\n';
  return 0;
}