#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = 1e15;
struct Fenwick {
  long long N;
  vector<long long> seg;
  Fenwick(long long N) : N(N) {
    seg.resize(N + 1);
    fill_n(begin(seg), N + 1, 0);
  }
  void add(long long i, long long x) {
    i++;
    while (i <= N) {
      seg[i] += x % mod;
      seg[i] %= mod;
      i += i & -i;
    }
  }
  long long sum(long long i) {
    long long s{0};
    while (i > 0) {
      s += seg[i];
      i -= i & -i;
    }
    return s % mod;
  }
  long long sum(long long a, long long b) { return (sum(b) - sum(a)) % mod; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> p;
  for (long long i = 0; i < k; i++) {
    long long l, r;
    cin >> l >> r;
    p.push_back(make_pair(l, r));
  }
  Fenwick tree(n);
  tree.add(0, 1);
  for (long long i = 1; i < n; i++) {
    long long plus = 0;
    for (long long j = 0; j < k; j++) {
      if (i - p[j].first >= 0) {
        plus += tree.sum(max(0ll, i - p[j].second), i - p[j].first + 1);
        plus %= mod;
      }
    }
    tree.add(i, plus);
  }
  cout << tree.sum(n, n + 1) << endl;
}
