#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> ways(n + 7, 0);
  ways[1] = 1;
  vector<pair<int, int>> pairs(k);
  for (auto &i : pairs) cin >> i.first >> i.second;
  sort(pairs.begin(), pairs.end());
  for (int i = 1; i <= n; i++) {
    for (auto j : pairs) {
      if (j.first > i) break;
      for (int k = j.first; k <= j.second; k++) {
        if (k > i) break;
        ways[i] = (ways[i] % 998244353 + ways[i - k] % 998244353) % 998244353;
      }
    }
  }
  cout << ways[n] << endl;
  return 0;
}
