#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  ll dp[n + 1] = {};
  dp[0] = 1;
  dp[1] = -1;
  rep(i, k) {
    cin >> l >> r;
    r++;
    v[i].first = l, v[i].second = r;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) (dp[i] += dp[i - 1]) %= mod;
    for (int j = 0; j < k; ++j) {
      l = v[j].first, r = v[j].second;
      if (i + l < n) (dp[i + l] += dp[i]) %= mod;
      if (i + r < n) (dp[i + r] -= dp[i]) %= mod;
      if (dp[i + r] < 0) dp[i + r] += mod;
    }
  }

  // rep(i, n - 1)(dp[i + 1] += dp[i]) %= mod;

  cout << dp[n - 1] << endl;
  return 0;
}