#include <bits/stdc++.h>
const double pi = 4 * atan(1);
using namespace std;
template <typename T>
void print_vec(const vector<T>& v) {
  for (int i = 0; i < ((int)(v.size())); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << "\n";
}
inline long long floorDiv(long long x, long long y) {
  long long d = x / y;
  long long r = x % y;
  return r ? (d - ((x < 0) ^ (y < 0))) : d;
}
long long ceilDiv(long long x, long long y) { return -floorDiv(-x, y); }
bool predicate(long long mid) { return mid > 10; }
long long bin_search(long long lo, long long hi) {
  int sign = lo < hi ? 1 : -1;
  lo *= sign;
  hi *= sign;
  hi++;
  while (lo < hi) {
    long long mid = floorDiv(lo + hi, 2);
    if (!predicate(sign * mid)) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }
  return sign * lo;
}
const long long MOD = 998244353;
const int MAXN = 200005;
class FenwickTree {
 private:
  vector<long long> ft;

 public:
  FenwickTree(int m) { ft.assign(m + 1, 0); }
  long long rsq(int j) {
    long long sum = 0;
    for (; j; j -= ((j) & -(j))) sum += ft[j];
    sum %= MOD;
    return sum;
  }
  long long rsq(int i, int j) {
    return (((rsq(j) - rsq(i - 1)) % MOD) + MOD) % MOD;
  }
  void update(int i, long long v) {
    for (; i < (int)ft.size(); i += ((i) & -(i))) ft[i] += v;
    ft[i] %= MOD;
  }
};
class RUPQ {
 private:
  FenwickTree ft;

 public:
  RUPQ(int m) : ft(FenwickTree(m)) {}
  void range_update(int ui, int uj, long long v) {
    ft.update(ui, v);
    ft.update(uj + 1, -v);
  }
  long long point_query(int i) { return ft.rsq(i); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> ranges;
  while (k--) {
    int a, b;
    cin >> a >> b;
    ranges.emplace_back(a, b);
  }
  RUPQ ft(n);
  ft.range_update(1, 1, 1);
  for (int i = 1; i < n; i++) {
    long long v = ft.point_query(i);
    for (auto p : ranges) {
      p.first += i;
      p.second += i;
      p.second = min(p.second, n);
      if (p.first > p.second) {
        continue;
      }
      ft.range_update(p.first, p.second, v);
    }
  }
  cout << ft.point_query(n) << "\n";
}
