#include <bits/stdc++.h>
using namespace std;
const int INF = 100100100;
const long long LINF = 1e18 + 100;
const int MOD = 1e9 + 7;
const int mod = 998244353;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  int N, K;
  cin >> N >> K;
  vector<int> c;
  for (int i = 0; i < (K); i++) {
    int l, r;
    cin >> l >> r;
    for (int i = (l); i < (r + 1); i++) {
      c.push_back(i);
    }
  }
  sort(c.begin(), c.end());
  mint ans = 0;
  vector<mint> memo(N + 1, 0);
  memo[N] = 1;
  int M = c.size();
  for (int i = N - 1; i > 0; i--) {
    mint ret = 0;
    for (int j = 0; j < (M); j++) {
      if (c[j] > N - i) break;
      ret += memo[i + c[j]];
    }
    memo[i] = ret;
  }
  cout << memo[1] << endl;
}
