#include <bits/stdc++.h>
using namespace std;
template <typename T>
void drop(const T &x) {
  cout << x << '\n';
  exit(0);
}
const long long mod = 998244353;
void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> t(n + 1);
  vector<int> s;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
      t[i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (t[i]) s.push_back(i);
  }
  vector<long long> dp(n + 1);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < (int)s.size(); j++) {
      if (i - s[j] < 1) continue;
      dp[i] = (dp[i] + dp[i - s[j]]) % mod;
    }
  }
  cout << dp[n] % mod << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) milkshake();
  return 0;
}
