#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  long long l, r;
  vector<long long> s;
  for (long long i = 0; i < (long long)(k); i++) {
    cin >> l >> r;
    for (long long j = l; j < r + 1; j++) {
      s.emplace_back(j);
    }
  }
  sort(s.begin(), s.end());
  vector<long long> dp(n + 1, -1);
  dp[1] = 1;
  for (long long i = 1; i < n + 1; i++) {
    if (dp[i] == -1) continue;
    for (long long j = 0; j < (long long)(s.size()); j++) {
      long long ele = s[j];
      if (ele + i > n) break;
      if (dp[i + ele] == -1) dp[i + ele] = 0;
      dp[i + ele] += dp[i];
      dp[i + ele] = dp[i + ele] % 998244353;
    }
  }
  if (dp[n] == -1)
    cout << "0" << endl;
  else
    cout << dp[n] << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
