#include <bits/stdc++.h>
using namespace std;
template <class T>
void read_v(T& x, std::istream& in) {
  in >> (x);
}
template <class A>
void read_vec(vector<A>& x, std::istream& in) {
  for (auto& a : x) read_v(a, in);
}
long long iceildiv(const long long a, const long long b) {
  if (a == 0) {
    return 0;
  }
  return (1 + ((a - 1) / b));
}
bool sortpairbysec(const pair<int, int>& a, const pair<int, int>& b) {
  return (a.second < b.second);
}
template <typename T>
T factmod(T a, T modulus) {
  int res = 1, i;
  for (i = 2; i <= a; i++) {
    res *= i;
    res %= modulus;
  }
  return res;
}
template <typename T>
int powmod(T a, T b, const int m) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans *= a;
      ans %= m;
    }
    a *= a;
    a %= m;
    b >>= 1;
  }
  return ans;
}
template <typename T>
int power(T a, T b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans *= a;
    }
    a *= a;
    b >>= 1;
  }
  return ans;
}
template <unsigned int MOD>
struct ModInt {
  using uint = unsigned int;
  using unsigned long long = unsigned long long;
  using M = ModInt;
  uint v;
  ModInt(long long _v = 0) { set_norm(_v % MOD + MOD); }
  M& set_norm(uint _v) {
    v = (_v < MOD) ? _v : _v - MOD;
    return *this;
  }
  explicit operator bool() const { return v != 0; }
  M operator+(const M& a) const { return M().set_norm(v + a.v); }
  M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }
  M operator*(const M& a) const {
    return M().set_norm(unsigned long long(v) * a.v % MOD);
  }
  M operator/(const M& a) const { return *this * a.inv(); }
  M& operator+=(const M& a) { return *this = *this + a; }
  M& operator-=(const M& a) { return *this = *this - a; }
  M& operator*=(const M& a) { return *this = *this * a; }
  M& operator/=(const M& a) { return *this = *this / a; }
  M operator-() const { return M() - *this; }
  M& operator++(int) { return *this = *this + 1; }
  M& operator--(int) { return *this = *this - 1; }
  M pow(long long n) const {
    if (n < 0) return inv().pow(-n);
    M x = *this, res = 1;
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const {
    long long a = v, b = MOD, p = 1, q = 0, t;
    while (b != 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(p -= t * q, q);
    }
    return M(p);
  }
  bool operator==(const M& a) const { return v == a.v; }
  bool operator!=(const M& a) const { return v != a.v; }
  friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
  static uint get_mod() { return MOD; }
};
using Mint = ModInt<998244353>;
Mint dp_solve(const int n, const vector<pair<int, int>>& sv) {
  int k = (int)(sv).size();
  vector<Mint> dp(n + 1, 0);
  for (auto x : sv) {
    dp[x.first] = 1;
    if (x.second <= n) {
      dp[x.second] = -1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i > 1) dp[i] += dp[i - 1];
    for (int j = 0; j < k; j++) {
      int l, r;
      tie(l, r) = sv[j];
      if (i + l <= n) {
        dp[i + l] += dp[i];
      }
      if (i + r <= n) {
        dp[i + r] -= dp[i];
      }
    }
  }
  Mint ans = dp[n - 1];
  return ans;
}
void ssolve(std::istream& in, std::ostream& out) {
  int n, k;
  in >> n >> k;
  vector<pair<int, int>> sv;
  for (int i = 0; i < (k); i++) {
    int l, r;
    in >> l >> r;
    r++;
    sv.emplace_back(make_pair(l, r));
  }
  sort(begin(sv), end(sv));
  Mint ans = dp_solve(n, sv);
  out << (ans) << endl;
  return;
}
class DLeapingTak {
 public:
  void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);
    int t;
    int READ = 0;
    if (READ)
      in >> t;
    else
      t = 1;
    while (t--) {
      ssolve(in, out);
    }
  }
};
int main() {
  DLeapingTak solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
}
