#include <bits/stdc++.h>
using namespace std;
int main() {
  const int mod1 = 998244353;
  int n, k;
  cin >> n >> k;
  vector<int> S;
  for (int i = 1; i <= k; ++i) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; ++j) S.push_back(j);
  }
  sort(S.begin(), S.end());
  vector<int> dp(n + 1);
  dp[0] = 1;
  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]]) %= mod1;
    }
  }
  cout << dp[n];
  return 0;
}
