#include <bits/stdc++.h>
using namespace std;
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y) {
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y) {
  return (x > y) ? y : x;
}
int gcd(int n1, int n2) {
  if (n2 != 0)
    return gcd(n2, n1 % n2);
  else
    return n1;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
clock_t time_p = clock();
void rtime() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int mod = 998244353;
  long long int dp[n];
  memset(dp, 0, sizeof(dp));
  set<long long int> coins;
  for (long long int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (long long int j = l; j <= r; j++) coins.insert(j);
  }
  vector<long long int> coin;
  for (auto itr = coins.begin(); itr != coins.end(); itr++) {
    coin.push_back(*itr);
  }
  long long int t = coin[0];
  for (long long int i = 0; i < t; i++) dp[i] = -1;
  dp[t] = 1;
  dp[0] = 1;
  for (long long int i = t + 1; i < n; i++) {
    for (long long int j = 0; j < coin.size(); j++) {
      if (coin[j] > i) continue;
      long long int ans = dp[i];
      dp[i] = ((dp[i - coin[j]]) % mod + ans) % mod;
    }
  }
  if (dp[n - 1] == -1)
    cout << 0;
  else
    cout << dp[n - 1];
}
