#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vin = vector<int>;
using vvin = vector<vin>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vst = vector<string>;
using P = pair<ll, ll>;
const int inf = 998244353;
const ll INF = 9e18;
const long double PI = acos(-1.0);
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[220000];
int main() {
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll l(k), r(k);
  for (ll i = 0; i < (k); ++i) cin >> l[i] >> r[i];
  dp[1] = 1;
  dp[2] = -1;
  for (ll i = 1; i < (n + 1); ++i) {
    dp[i] = (dp[i] + dp[i - 1]) % inf;
    for (ll j = 0; j < (k); ++j) {
      dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % inf;
      dp[i + r[j] + 1] = (dp[i + r[j] + 1] - dp[i]) % inf;
    }
  }
  if (dp[n] < 0) dp[n] += inf;
  cout << dp[n] << endl;
}
