#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6;
const long long MOD = 998244353;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;
map<int, int> dp;
int n, k;
long long countWays(int curr, set<int> opts) {
  if (curr == n) {
    return 1;
  }
  if (curr > n) {
    return 0;
  }
  if (dp.count(curr)) {
    return dp[curr];
  }
  long long res = 0;
  for (int idx : opts) {
    res += countWays(curr + idx, opts) % MOD;
  }
  res %= MOD;
  dp[curr] = res;
  return res;
}
int main() {
  cin >> n >> k;
  set<int> opts;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    while (l <= r) {
      opts.insert(l);
      l++;
    }
  }
  cout << countWays(1, opts) << endl;
}
