#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
using vector<long long> = vector<long long>;
using vll = vector<vector<long long>>;
using vpll = vector<pll>;
struct Edge {
  long long to;
  long long cost;
};
struct edge {
  long long from;
  long long to;
  long long cost;
};
using Graph = vector<vector<Edge>>;
using graph = vector<vector<edge>>;
const int MAX = 10000000;
const long long MOD = 998244353;
const double PI = 3.1415926535897932;
const long long INF = 1LL << 60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void debug_out() { std::cout << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long n, k;
vector<long long> l, r;
int solve() {
  cin >> n >> k;
  l.resize(k);
  r.resize(k);
  vector<long long> s;
  for (long long i = (0); i < (k); i++) {
    cin >> l[i] >> r[i];
    for (long long j = (l[i]); j < (r[i] + 1); j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  vector<long long> dp(2 * n + 1);
  for (long long i = (0); i < (s.size()); i++) {
    dp[s[i]] = 1;
  }
  for (long long i = (1); i < (n); i++) {
    for (long long j = (0); j < (s.size()); j++) {
      if (i + s[j] > n) continue;
      dp[i + s[j]] += dp[i];
      dp[i + s[j]] %= MOD;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
int main() {
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int end_solve = solve();
  return end_solve;
}
