#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 998244353;
const int64_t MAXN = 200100;
int64_t memo[MAXN * 2];

int main()
{
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> L(K), R(K);
  for (int i = 0; i < K; i++)
  {
    cin >> L.at(i) >> R.at(i);
  }
  memo[0] = 1;
  memo[1] = (MOD - 1) % MOD;
  for (int i = 0; i < N; i++)
  {
    if (i)
    {
      (memo[i] += memo[i - 1]) %= MOD;
    }
    int64_t cur = memo[i];
    for (int j = 0; j < K; j++)
    {
      int64_t l = L[j], r = R[j];
      (memo[i + l] += cur) %= MOD;
      (memo[i + r + 1] = memo[i + r + 1] - cur + MOD) %= MOD;
    }
  }
  cout << memo[N - 1] % MOD << endl;
}