#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
const int mod = 1e9 + 7;
const int mxN = 2e6 + 3;
vector<int> x_vec = {-1, 1, 0, 0};
vector<int> y_vec = {0, 0, -1, 1};
int main() {
  int modd = 998244353;
  int n, k;
  cin >> n >> k;
  int l[10], r[10];
  for (int i = 0; i < k; i++) cin >> l[i] >> r[i];
  int dp[200010] = {};
  int fly[200010] = {};
  int quantity = 0;
  for (int i = 0; i < k; i++) {
    for (int j = l[i]; j <= r[i]; j++) fly[quantity++] = j;
  }
  sort(fly, fly + quantity);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < quantity; j++) {
      if (i - fly[j] > 0) {
        dp[i] += dp[i - fly[j]];
        dp[i] %= modd;
      } else
        break;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
