#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
int dp[400000];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> d(200001);
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    for (int j = a; j <= b; j++) d[j]++;
  }
  vector<int> data;
  for (int i = 0; i < 200001; i++)
    if (d[i] != 0) data.emplace_back(i);
  for (int i = 0; i < 400000; i++) dp[i] = 0;
  dp[1] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < data.size(); j++) {
      dp[i + data[j]] += dp[i];
      dp[i + data[j]] %= 998244353;
    }
  }
  cout << dp[n] << endl;
  return 0;
}
