#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for (auto i = 0; i < k; ++i) {
    cin >> l[i] >> r[i];
    r[i]++;
  }
  const int mod = 998244353;
  vector<int> acc(n + 1), dp(n + 1);
  dp[1] = acc[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i] += acc[max(0, i - l[j])];
      if (i >= r[j]) dp[i] -= acc[i - r[j]];
      if (dp[i] < 0) dp[i] += mod;
      if (dp[i] >= mod) dp[i] -= mod;
    }
    acc[i] = acc[i - 1] + dp[i];
    if (acc[i] >= mod) acc[i] -= mod;
  }
  cout << dp[n] << endl;
}
