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