#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  for (const auto& x : v) {
    out << x << ", ";
  }
  return out << "]";
}
template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) {
    in >> x;
  }
  return in;
}
template <typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T>& p) {
  return out << "{" << p.first << ", " << p.second << "}";
}
constexpr int MOD = 998244353;
struct fenwick_t {
  int ft[1000000];
  int query(int w) {
    ++w;
    int a = 0;
    for (; w; w -= (w & -w)) {
      a = (a + ft[w]) % MOD;
    }
    return a;
  }
  void update(int w, int v) {
    ++w;
    for (; w < 1000000; w += w & (-w)) {
      ft[w] = (ft[w] + v) % MOD;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for (int k = 0; k < K; ++k) {
    cin >> L[k] >> R[k];
  }
  fenwick_t ft;
  ft.update(1, 1);
  for (int n = 2; n <= N; ++n) {
    int x = 0;
    for (int k = 0; k < K; ++k) {
      x = (x + ft.query(max(0, n - L[k])) - ft.query(max(0, n - R[k] - 1))) %
          MOD;
    }
    ft.update(n, x);
  }
  cout << ft.query(N) - ft.query(N - 1) << "\n";
  return 0;
}
