#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
using vec2 = vector<vector<T>>;
template <typename T>
using vec3 = vec2<vector<T>>;
template <typename T>
using vec4 = vec3<vector<T>>;
template <typename T>
using vec5 = vec4<vector<T>>;
template <typename T>
using vec6 = vec5<vector<T>>;
ll MOD = 998244353;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> starts;
  vector<int> ends;
  for (int i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    starts.push_back(l);
    ends.push_back(r);
  }
  vector<ll> dp(N + 1, 0);
  vector<int> ok(N + 1, 0);
  ok[0] = 1;
  dp[0] = 1;
  dp[1] = -1;
  for (int i = 0; i < N; i++) {
    if (i != 0) ok[i] += ok[i - 1];
    if (i != 0) {
      dp[i] += dp[i - 1];
      dp[i] %= MOD;
    }
    if (ok[i] == 0) continue;
    for (int j = 0; j < K; j++) {
      int s = starts[j];
      int e = ends[j];
      dp[i + s] += dp[i];
      dp[i + s] %= MOD;
      ok[i + s]++;
      ok[min(i + e + 1, N)]--;
      dp[min(i + e + 1, N)] -= dp[i];
      dp[min(i + e + 1, N)] += MOD;
      dp[min(i + e + 1, N)] %= MOD;
    }
  }
  cout << dp[N - 1] << endl;
}
