#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 998244353;
const double pi = M_PI;
class BinaryIndexedTree {
 public:
  BinaryIndexedTree(ll n);
  void add(ll i, ll x);
  ll sum(ll i);

 private:
  vector<ll> nodes;
  void init(ll n);
};
BinaryIndexedTree::BinaryIndexedTree(ll n) { init(n); }
void BinaryIndexedTree::init(ll n) {
  for (ll i = 0; i < n + 1; i++) {
    nodes.push_back(0);
  }
}
void BinaryIndexedTree::add(ll i, ll x) {
  while (i <= nodes.size()) {
    nodes[i] += x;
    i += i & -i;
  }
}
ll BinaryIndexedTree::sum(ll i) {
  ll result = 0;
  while (i > 0) {
    result += nodes[i] % mod;
    i -= i & -i;
  }
  return result;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> range(k);
  for (int i = 0, i_len = (k); i < i_len; ++i) {
    int l, r;
    cin >> l >> r;
    r++;
    range[i] = {l, r};
  }
  BinaryIndexedTree bit(n);
  bit.add(1, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int lindex = i - range[j].second <= 0 ? 0 : i - range[j].second;
      int rindex = i - range[j].first <= 0 ? 0 : i - range[j].first;
      ll sum = (bit.sum(rindex) - bit.sum(lindex)) % mod;
      bit.add(i, sum);
    }
  }
  cout << bit.sum(n) - bit.sum(n - 1) << endl;
}
