#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long sum(long long a, long long b) { return (a + b) % MOD; }
struct segment_tree {
  vector<long long> t;
  segment_tree(int n) { t.resize(n << 2); }
  void update(int v, int tl, int tr, int l, int r, int val) {
    if (l > r) return;
    if (l == tl && r == tr) {
      t[v] = sum(t[v], val);
      return;
    }
    int tm = (tl + tr) / 2;
    t[v * 2] = sum(t[v * 2], t[v]);
    t[v * 2 + 1] = sum(t[v * 2 + 1], t[v]);
    t[v] = 0;
    update(v * 2, tl, tm, l, min(r, tm), val);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
  }
  long long get(int v, int tl, int tr, int pos) {
    if (tl == tr) return t[v];
    int tm = (tl + tr) / 2;
    t[v * 2] = sum(t[v * 2], t[v]);
    t[v * 2 + 1] = sum(t[v * 2 + 1], t[v]);
    t[v] = 0;
    if (pos <= tm)
      get(v * 2, tl, tm, pos);
    else
      get(v * 2 + 1, tm + 1, tr, pos);
  }
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> a(k);
  for (int i = 0; i < k; i++) cin >> a[i].first >> a[i].second;
  segment_tree se(n);
  se.update(1, 0, n - 1, 0, 0, 1);
  for (int i = 0; i < n; i++) {
    long long val = se.get(1, 0, n - 1, i);
    for (auto &now : a)
      se.update(1, 0, n - 1, i + now.first, min(i + now.second, n - 1), val);
  }
  cout << se.get(1, 0, n - 1, n - 1);
  return 0;
}
