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