#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI = acos(-1);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> A;
  for (int i = (0); i < (int)(k); i++) {
    ll a, b;
    cin >> a >> b;
    for (int j = (a); j < (int)(b + 1); j++) {
      A.push_back(j);
    }
  }
  vector<ll> dp(200010, 0);
  dp[1] = 1;
  for (int i = (1); i < (int)(n + 1); i++) {
    for (auto j : A) {
      if (i - j >= 0) {
        dp[i] = (dp[i] + (dp[i - j] % MOD)) % MOD;
      }
    }
  }
  ll ans = dp[n] % MOD;
  cout << ans << endl;
}
