#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[200001];
long long goal;
vector<long long> s;
long long step(long long now) {
  dp[now - 1] = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (now - 1 + s[i] >= 200001) continue;
    if (dp[now - 1 + s[i]] != -1) {
      dp[now - 1] += dp[now - 1 + s[i]];
      dp[now - 1] %= 998244353;
    }
  }
  if (now - 1)
    return step(now - 1);
  else
    return dp[now];
}
int main(int argc, char **argv) {
  (void)argc;
  (void)argv;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  for (long long i = 0; i < 200001; i++) dp[i] = -1;
  long long n, k;
  cin >> n >> k;
  goal = n;
  dp[n] = 1;
  long long l[k], r[k];
  for (long long i = 0; i < k; i++) cin >> l[i] >> r[i];
  for (long long i = 0; i < k; i++) {
    for (long long j = l[i]; j < r[i] + 1; j++) s.push_back(j);
  }
  long long ans = step(n);
  cout << ans << endl;
  return 0;
}
