#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const int MOD = 998244353;
const int MAXN = 2e5 + 5;
int N, K;
int bit[MAXN];
void update(int i, int delta) {
  for (; i <= N + 1; i += i & -i) {
    bit[i] += delta;
    bit[i] %= MOD;
  }
}
void range_update(int l, int r, int delta) {
  update(l, delta);
  update(r + 1, -delta);
}
int point_query(int i) {
  int sum = 0;
  for (; i > 0; i -= i & -i) {
    sum += bit[i];
    sum %= MOD;
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  vector<pair<int, int>> ranges(K);
  for (auto &range : ranges) {
    cin >> range.first >> range.second;
  }
  for (int i = 1; i <= N; i++) bit[i] = 0;
  range_update(1, 1, 1);
  for (int i = 1; i <= N; i++) {
    int delta = point_query(i);
    for (auto range : ranges) {
      int begin = i + range.first;
      if (begin > N) continue;
      int end = min(i + range.second, N);
      range_update(begin, end, delta);
    }
  }
  cout << point_query(N) << endl;
  return 0;
}
