#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &A) {
  for (long long i = 0; i < A.size(); i++) os << A[i] << " ";
  os << endl;
  return os;
}
template <>
ostream &operator<<(ostream &os, const vector<vector<long long> > &A) {
  long long N = A.size();
  for (long long i = 0; i < N; i++) {
    for (long long j = 0; j < A[i].size(); j++) os << A[i][j] << " ";
    os << endl;
  }
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
struct edge {
  long long from, to, d, c, i;
  edge(long long _from = 0, long long _to = 0, long long _d = 0,
       long long _c = 0) {
    from = _from;
    to = _to;
    d = _d;
    c = _c;
  }
  bool operator<(const edge &rhs) const {
    return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
  }
};
struct aabb {
  long long x1, y1, x2, y2;
  aabb(long long x1, long long y1, long long x2, long long y2)
      : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
struct flow {
  long long to, cap, rev, cost;
  flow(long long to = 0, long long cap = 0, long long rev = 0,
       long long cost = 0)
      : to(to), cap(cap), rev(rev), cost(cost) {}
};
const long long di[4] = {0, -1, 0, 1};
const long long dj[4] = {-1, 0, 1, 0};
const long long ci[5] = {0, 0, -1, 0, 1};
const long long cj[5] = {0, -1, 0, 1, 0};
const long long LINF = LLONG_MAX / 2;
const long long INF = INT_MAX / 2;
const long double PI = acos(-1);
long long pow2(long long n) { return 1LL << n; }
template <typename T, typename U>
bool chmin(T &x, const U &y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template <typename T, typename U>
bool chmax(T &x, const U &y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
struct initializer {
  initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
struct BIT {
  vector<long long> container;
  BIT(long long n) { container = vector<long long>(n + 1, 0); }

 private:
  void internal_add(long long i, long long x) {
    if (i >= container.size() || i <= 0) return;
    (container[i] += x) %= 998244353;
    internal_add(i + (i & -i), x);
  }
  long long internal_sum(long long i) {
    if (i == 0) return 0;
    return (container[i] + internal_sum(i - (i & -i))) % 998244353;
  }

 public:
  void add(long long i, long long x) { internal_add(i + 1, x); }
  long long sum(long long r) { return internal_sum(r + 1); }
  long long sum(long long l, long long r) {
    return internal_sum(r - 1 + 1) - internal_sum(l - 1 + 1);
  }
};
long long N, M, K, T, Q, H, W;
signed main() {
  cin >> N >> K;
  vector<pair<long long, long long> > A(K);
  for (long long i = 0; i < (long long)(K); i++)
    cin >> A[i].first >> A[i].second;
  BIT bt(N + 10);
  bt.add(0, 1);
  for (long long i = 0; i < (long long)(N); i++) {
    for (long long j = 0; j < (long long)(K); j++) {
      long long l, r;
      tie(l, r) = A[j];
      long long tmp = bt.sum(max(0LL, i - r), max(0LL, i - l + 1));
      bt.add(i, tmp);
    }
  }
  cout << bt.sum(N - 1, N) << endl;
  return 0;
}
