#include <bits/stdc++.h>
using namespace std;
long dp[200007] = {}, sumdp[200007] = {}, mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  dp[0] = 1;
  sumdp[0] = 0;
  sumdp[1] = 1;
  int l[k], r[k];
  for (int i = 0; i < (int)(k); i++) cin >> l[i] >> r[i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < (int)(k); j++) {
      int x = i - l[j], y = max(i - r[j], 0);
      if (x < y) continue;
      dp[i] += sumdp[x + 1] - sumdp[y];
    }
    if (dp[i] < 0) dp[i] += mod;
    sumdp[i + 1] = sumdp[i] + dp[i];
    sumdp[i + 1] %= mod;
  }
  cout << dp[n - 1] << endl;
}
