#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const int mod = 998244353;
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<pair<int, int> > lr(k);
  for (int i = 0; i < (k); i++) {
    cin >> lr[i].first >> lr[i].second;
  }
  vector<long long> dp(200010);
  dp[0] = 1;
  dp[1] = -1;
  long long now = 0;
  for (int i = 0; i < (n); i++) {
    (now += dp[i]) % mod;
    for (int j = 0; j < (k); j++) {
      int left = min(i + lr[j].first, n);
      int right = min(i + lr[j].second, n);
      dp[left] += now;
      dp[right + 1] -= now;
    }
  }
  cout << now % mod << endl;
  return 0;
}
