#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool maxs(T& x, const T& y) {
  if (x < y) {
    x = y;
    return true;
  } else
    return false;
}
const int MX = 200005;
const int mod = 998244353;
long long int dp[MX];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<pair<int, int> > p(k);
  for (int i = 0; i < (k); ++i) cin >> p[i].first >> p[i].second;
  dp[0] = 0;
  dp[1] = 1;
  for (int i = 1; i <= (n); ++i)
    if (i > 1) {
      long long int now = 0;
      for (int j = 0; j < (k); ++j) {
        int l = i - p[j].second - 1, r = i - p[j].first;
        maxs(l, 0);
        maxs(r, 0);
        now += dp[r];
        now -= dp[l];
      }
      dp[i] = dp[i - 1] + now;
      dp[i] %= mod;
    }
  cout << dp[n] - dp[n - 1] << endl;
  return 0;
}
