#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
inline void fastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
int main() {
  fastIO();
  long long int n, k;
  cin >> n >> k;
  vector<long long int> dp(n + 10);
  vector<long long int> coins;
  for (int i = 0; i < k; i++) {
    long long int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      coins.push_back(j);
      dp[j] = 1;
    }
  }
  sort(coins.begin(), coins.end());
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < coins.size(); j++) {
      if (coins[j] >= i) break;
      if (coins[j] < i) {
        dp[i] += dp[i - coins[j]];
        dp[i] %= MOD;
      }
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
