#include <bits/stdc++.h>
using namespace std;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
long long MOD = 998244353;
void chmax(long long &a, long long b) {
  if (a < b) a = b;
}
void chmin(long long &a, long long b) {
  if (a > b) a = b;
}
long long mod_pow(long long N, long long M) {
  if (M == 0) return 1;
  long long res = mod_pow((N * N) % MOD, M / 2);
  if (M & 1) res = (res * N) % MOD;
  return res %= MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long dp[200005];
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  long long N;
  int K;
  cin >> N >> K;
  vector<long long> move;
  for (int i = 0; i < K; i++) {
    int f, t;
    cin >> f >> t;
    for (int j = f; j <= t; j++) {
      move.push_back(j);
    }
  }
  sort(move.begin(), move.end());
  for (int i = 0; i < 200005; i++) dp[i] = 0;
  dp[N] = 1;
  for (long long i = N; i >= 1; i--) {
    for (int j = 0; j < move.size(); j++) {
      if (i - move.at(j) < 1) break;
      dp[i - move.at(j)] += dp[i];
      dp[i - move.at(j)] %= MOD;
    }
  }
  cout << dp[1] << endl;
}
