#include <bits/stdc++.h>
using namespace std;
long powP(long a, long b) {
  if (b == 1)
    return a;
  else if (b == 0)
    return 1;
  else if (b < 0)
    return powP(a, 1000000007 + b - 1);
  else
    return (powP(a, b / 2) * powP(a, b / 2 + b % 2)) % 1000000007;
}
template <typename T>
using vec = vector<T>;
template <typename T>
using vvec = vector<vector<T>>;
int main() {
  int n, k;
  cin >> n >> k;
  vec<bool> v(n + 1, 0);
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      v[j] = 1;
    }
  }
  vec<long long> dp(n + 1, 0);
  dp[n] = 1;
  for (size_t i = n - 1; i > 0; i--) {
    for (int j = i + 1; j <= n; j++) {
      dp[i] += dp[j] * v[j - i];
      dp[i] %= 998244353;
    }
  }
  cout << dp[1];
}
