#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 123;
const double PI = acos(-1);
const long long MOD = 998244353;
long long dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
long long dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
long long dx8[] = {+1, +1, -1, -1, +2, +2, -2, -2};
long long dy8[] = {+2, -2, +2, -2, +1, -1, +1, -1};
long long powmod(long long a, long long b) {
  a %= MOD;
  if (!a) return 0;
  long long pr = 1;
  while (b > 0) {
    if (b & 1) {
      pr *= a;
      pr %= MOD;
      --b;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return pr;
}
long long modinverse(long long a) { return powmod(a, MOD - 2); }
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6) {
    if (n % i == 0 or n % (i + 2) == 0) return false;
  }
  return true;
}
void seive(bool a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 3; ii <= mx; ii += 2)
    if (!a[ii])
      for (jj = ii * ii; jj < N; jj += 2 * ii) a[jj] = true;
}
void numofdiv(long long a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 1; ii <= mx; ii++) {
    for (jj = ii * ii; jj < N; jj += ii) {
      if (jj == ii * ii)
        a[jj]++;
      else
        a[jj] += 2;
    }
  }
}
void sumofdiv(long long a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 1; ii <= mx; ii++) {
    for (jj = ii * ii; jj < N; jj += ii) {
      if (jj == ii * ii)
        a[jj] += ii;
      else
        a[jj] += ii + jj / ii;
    }
  }
}
long long n, m, dp[200005];
long long x[200005];
vector<long long> v;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  long long i, j;
  while (m--) {
    long long a, b;
    cin >> a >> b;
    x[a]++;
    x[b + 1]--;
  }
  for (i = 1; i < n; i++) {
    x[i] += x[i - 1];
    if (x[i] > 0) v.push_back(i);
  }
  dp[1]++;
  for (i = 2; i <= n; i++) {
    if (dp[i]) continue;
    for (j = 0; j < v.size() and v[j] < i; j++) {
      dp[i] += dp[i - v[j]];
      dp[i] %= MOD;
    }
  }
  cout << dp[n] << '\n';
}
