#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 998244353;
const double pi = M_PI;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> range(k);
  for (int i = 0, i_len = (k); i < i_len; ++i) {
    int l, r;
    cin >> l >> r;
    r++;
    range[i] = {l, r};
  }
  vl dp(n + 1, 0);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] += dp[i - 1];
    dp[i] % mod;
    for (int j = 0; j < k; j++) {
      int lindex = i - range[j].second <= 0 ? 0 : i - range[j].second;
      int rindex = i - range[j].first <= 0 ? 0 : i - range[j].first;
      ll sum = (dp[rindex] - dp[lindex]) % mod;
      dp[i] += sum;
      dp[i] %= mod;
    }
  }
  cout << dp[n] - dp[n - 1] << endl;
}
