#include <bits/stdc++.h>
int dp[200001];
using namespace std;
int main() {
  int n, k, p = 998244353;
  cin >> n >> k;
  int l[k + 1], r[k + 1];
  for (int i = 1; i <= k; i++) {
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  vector<int> v(n + 1);
  for (int i = 1; i <= k; i++) {
    for (int g = l[i]; g <= r[i]; g++) v.push_back(g);
  }
  for (int i = 2; i <= n; i++) {
    for (int g = 0; g <= v.size() - 1; g++) {
      if (i - v[g] > 0) {
        dp[i] += dp[i - v[g]];
        dp[i] %= p;
      }
    }
  }
  cout << dp[n];
}
