#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(998244353);
int n, k;
vector<int> s;
vector<vector<int>> lr;
vector<ll> dp;
void f(int i, int l, int r) {
  for (int j = l; j <= r; j++) dp[i] = (dp[i] + dp[j]) % MOD;
}
int main(void) {
  cin >> n >> k;
  lr = vector<vector<int>>(k, vector<int>(2));
  for (int i = 0; i < k; i++) {
    cin >> lr[i][0] >> lr[i][1];
  }
  for (int i = 0; i < k; i++) {
    int minarg = i;
    for (int j = i + 1; j < k; j++) {
      if (lr[minarg][0] > lr[j][0]) minarg = j;
    }
    swap(lr[i][0], lr[minarg][0]);
    swap(lr[i][1], lr[minarg][1]);
  }
  dp = vector<ll>(n, 0);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k && lr[j][0] <= i; j++) {
      int l = max(i - lr[j][1], 0);
      int r = max(i - lr[j][0], 0);
      f(i, l, r);
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
