#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long n, dp[200005];
int k;
vector<int> v;
int main() {
  cin >> n >> k;
  n--;
  while (k--) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) v.push_back(i);
  }
  sort(v.begin(), v.end());
  dp[0] = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < v.size() && v[j] + i <= n; j++) {
      dp[i + v[j]] += dp[i];
      if (dp[i + v[j]] > MOD) dp[i + v[j]] -= MOD;
    }
  cout << dp[n] << endl;
  return 0;
}
