#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return (a % b) ? gcd(b, a % b) : b;
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
int main(void) {
  int n, k;
  cin >> n >> k;
  n--;
  set<int> s;
  for (int i = 0; i < (k); ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      s.insert(j);
    }
  }
  vector<long long> dp(n + 3, 0);
  dp[0] = 1;
  for (int i = 0; i < n + 3; i++) {
    for (auto itr = s.begin(); itr != s.end(); ++itr) {
      if (i + *itr > n) continue;
      dp[i + *itr] = dp[i] + dp[i + *itr] % 998244353;
    }
  }
  cout << dp[n] % 998244353 << endl;
  return 0;
}
