#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 1e6 + 5;
long long inf = 1e18;
bool a[N];
long long second[N];
long long id = 0;
long long dp[N];
long long b[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      a[j] = true;
    }
  }
  for (int i = 1; i < N; i++) {
    if (a[i]) {
      second[id++] = i;
    }
  }
  dp[second[0]] = 1;
  long long ib = 0;
  b[ib] = second[ib];
  ib++;
  for (int i = second[0] + 1; i <= n; i++) {
    if (second[ib] < i) {
      b[ib] = second[ib];
      ib++;
    }
    for (int j = ib - 1; j >= 0; j--) {
      dp[i] += dp[i - b[j]];
      dp[i] %= mod;
    }
  }
  cout << dp[n];
  return 0;
}
