#include <bits/stdc++.h>
#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
using namespace std;
template <class T>
using Graph = vector<vector<T>>;
const long double pi = M_PI;
const int64_t MOD = 998244353;
const int64_t INF = 1LL << 62;
int64_t Floor(int64_t a, int64_t b) { return (a - (a % b)) / b; }
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline T Gcd(T a, T b) {
  T c;
  while (b) {
    c = b;
    b = a % b;
    a = c;
  }
  return a;
}
int64_t Lcm(int64_t a, int64_t b) {
  if (a < b) {
    swap(a, b);
  }
  return a / Gcd(a, b) * b;
}
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> ans(n + n + 5, 0), s;
  ans[0] = 1;
  for (int64_t i = 0; i < k; i++) {
    int64_t l, r;
    cin >> l >> r;
    for (int64_t j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  sort((s).begin(), (s).end());
  for (int64_t i = 1; i <= n; i++) {
    for (auto e : s) {
      if (0 <= i - e) {
        ans[i] += ans[i - e];
        ans[i] %= MOD;
      } else {
        break;
      }
    }
  }
  cout << ans[n - 1] << endl;
  return 0;
}
