#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmin(T& x, T a) {
  if (x >= a) {
    x = a;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T& x, T a) {
  if (x <= a) {
    x = a;
    return true;
  }
  return false;
}
const long long mod = 998244353LL;
class modlong {
 public:
  modlong() { x = 0; }
  modlong(long long num) { x = adjust(num); }
  inline operator long long() const { return x; }
  inline bool operator==(long long num) { return this->x == num; }
  inline bool operator!=(long long num) { return !(*this == num); }
  inline void operator=(long long num) { x = adjust(num); }
  inline void operator+=(long long num) { x = adjust(x + num); }
  inline void operator++() { this->operator+=(1); }
  inline modlong operator+(long long num) const {
    modlong m(this->x);
    m += num;
    return m;
  }
  inline void operator-=(long long num) { x = adjust(x - num); }
  inline void operator--() { this->operator-=(1); }
  inline modlong operator-(long long num) {
    modlong m(this->x);
    m -= num;
    return m;
  }
  inline void operator*=(long long num) { x = adjust(x * num); }
  inline modlong operator*(long long num) {
    modlong m(this->x);
    m *= num;
    return m;
  }
  inline void operator/=(long long num);
  inline modlong operator/(long long num);

 private:
  inline long long adjust(long long a) {
    if (a >= mod) {
      return a % mod;
    }
    if (a < 0) {
      return mod - 1 + ((a + 1) % mod);
    }
    return a;
  }
  long long x;
};
inline modlong mod_inv(modlong a) {
  const long long inv_max = 300000;
  static vector<long long> inv;
  if (inv.size() == 0) {
    inv.resize(inv_max);
    for (int i = 0; i < inv_max; i++) {
      if (i <= 1) {
        inv[i] = i;
      } else {
        inv[i] = ((mod - mod / i) * inv[mod % i]) % mod;
      }
    }
  }
  long long p = mod, q = a, r;
  modlong m = 0, n = 1, c;
  while (1) {
    if (q < inv_max) {
      return n * inv[q];
    }
    c = p / q;
    r = p % q;
    c = m - n * c;
    p = q, q = r;
    m = n, n = c;
  }
}
inline modlong mod_div(modlong a, modlong b) { return a * mod_inv(b); }
inline void modlong::operator/=(long long num) { x = mod_div(*this, num); }
inline modlong modlong::operator/(long long num) {
  modlong m(this->x);
  m /= num;
  return m;
}
inline modlong mod_pow(modlong x, long long n) {
  if (n < 0) {
    x = mod_inv(x);
    n = -n;
  }
  n = n % (mod - 1);
  modlong temp = x, ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans *= temp;
    }
    temp *= temp;
    n >>= 1;
  }
  return ans;
}
inline modlong mod_log(modlong a, modlong x) {
  long long A = sqrt(mod);
  long long B = (mod + A - 1) / A;
  map<long long, long long> mp1, mp2;
  long long p0 = a;
  long long q0 = mod_pow(a, -A);
  long long p = 1;
  long long q = x;
  for (int i = 0; i < A; i++) {
    mp1.insert({p, i});
    p = (p * p0) % mod;
  }
  for (int i = 0; i < B; i++) {
    mp2.insert({q, A * i});
    q = (q * q0) % mod;
  }
  auto itr1 = mp1.begin();
  auto itr2 = mp2.begin();
  while (itr1 != mp1.end() && itr2 != mp2.end()) {
    if (itr1->first < itr2->first) {
      itr1++;
    } else if (itr1->first == itr2->first) {
      return itr1->second + itr2->second;
    } else {
      itr2++;
    }
  }
  return 0;
}
inline modlong mod_factorial(modlong n, bool inverse = false) {
  static vector<long long> factorial, factorial_inv;
  long long M = factorial.size();
  if (M <= n) {
    if (M == 0) {
      factorial.push_back(1);
      factorial_inv.push_back(1);
      M++;
    }
    if (M == 1) {
      factorial.push_back(1);
      factorial_inv.push_back(1);
      M++;
    }
    for (long long i = M; i <= n; i++) {
      factorial.push_back((factorial.back() * i) % mod);
      factorial_inv.push_back((factorial_inv.back() * mod_inv(i)) % mod);
    }
  }
  if (inverse == true) {
    return factorial_inv[n];
  } else {
    return factorial[n];
  }
}
inline modlong mod_combination(modlong n, modlong r) {
  assert(r <= n);
  return mod_factorial(n) * mod_factorial(n - r, true) * mod_factorial(r, true);
}
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<modlong> ans(N, 0);
  vector<modlong> sum(N, 0);
  ans[0] = 1;
  sum[0] = 1;
  vector<pair<int, int>> v;
  for (int k = 0; k < K; k++) {
    int L, R;
    cin >> L >> R;
    v.push_back({L, R + 1});
  }
  for (int i = 1; i < N; i++) {
    for (int k = 0; k < K; k++) {
      int l = i - v[k].second;
      int r = i - v[k].first;
      if (r < 0) {
        continue;
      }
      ans[i] += sum[r];
      if (l >= 0) {
        ans[i] -= sum[l];
      }
      sum[i] = sum[i - 1] + ans[i];
    }
  }
  cout << ans[N - 1] << '\n';
  return 0;
}
