#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2000000;
int dp[MAX_N];
int dp_sum[MAX_N];
int main() {
  int n, k;
  cin >> n >> k;
  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < MAX_N; i++) {
    dp[i] = 0;
    dp_sum[i] = 0;
  }
  dp[1] = 1;
  dp_sum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int li = i - l[j];
      int ri = i - r[j] - 1;
      if (li <= 0) continue;
      dp[i] = (((dp[i] + dp_sum[li]) % 998244353) - dp_sum[ri]) % 998244353;
    }
    dp_sum[i] = (dp[i] + dp_sum[i - 1]) % 998244353;
  }
  cout << dp[n] << endl;
}
