#include <bits/stdc++.h>
using namespace std;
int main() {
  long long mod = 998244353;
  int n, k;
  set<int> vals;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) vals.insert(i);
  }
  long long ways[n + 1];
  memset(ways, 0, sizeof(ways));
  ways[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto x : vals) {
      if (x >= i) break;
      ways[i] = (ways[i] + ways[i - x]) % mod;
    }
  }
  cout << ways[n] << "\n";
}
