#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int SEG_LEN = 16;
using ll = long long;
int main() {
  int N, K;
  cin >> N >> K;
  set<int> S;
  vector<int> L(K), R(K);
  for (int i = 0; i < K; ++i) {
    cin >> L[i] >> R[i];
    for (int d = L[i]; d <= R[i]; ++d) S.insert(d);
  }
  vector<ll> dp(N);
  dp[N - 1] = 1;
  vector<ll> seg(2 * SEG_LEN);
  auto add = [&](int idx, int val) {
    idx += SEG_LEN;
    seg[idx] = (seg[idx] + val) % MOD;
    while (true) {
      idx /= 2;
      if (idx == 0) break;
      seg[idx] = (seg[idx * 2] + seg[idx * 2 + 1]) % MOD;
    }
  };
  add(N - 1, 1);
  auto sum = [&](int l, int r) {
    l += SEG_LEN;
    r += SEG_LEN;
    ll res = 0;
    while (l < r) {
      if (l % 2 == 1) {
        res = (res + seg[l]) % MOD;
        ++l;
      }
      l /= 2;
      if (r % 2 == 1) {
        res = (res + seg[r - 1]) % MOD;
        --r;
      }
      r /= 2;
    }
    return res;
  };
  for (int i = N - 1; i >= 0; --i) {
    for (int k = 0; k < K; ++k) {
      if (i + R[i] < N) {
        dp[i] = (dp[i] + sum(i + L[k], i + R[k] + 1)) % MOD;
        add(i, dp[i]);
      }
    }
  }
  cout << dp[0] << endl;
}
