#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
const long long mod = 998244353;
long long bit[N];
void update(long long i, long long v) {
  for (; i < N; i += i & -i) {
    (bit[i] += v) %= mod;
  }
}
long long get(long long i) {
  long long v = 0;
  for (; i; i -= i & -i) {
    (v += bit[i]) %= mod;
  }
  return v;
}
void Main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > a(k);
  for (auto &i : a) cin >> i.first >> i.second;
  update(1, 1);
  for (long long i = 2; i <= n; i++) {
    for (auto &j : a) {
      long long u = get(max(0ll, i - j.second - 1));
      long long v = get(max(0ll, i - j.first));
      update(i, (v - u + mod * mod) % mod);
    }
  }
  cout << get(n) - get(n - 1) << '\n';
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  long long T = 1;
  while (T--) Main();
}
