#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
const int N = 200001;
vector<int> adj[N];
long long int mod = 998244353;
long long int mytree[4 * N];
long long int lazy[4 * N];
long long int arr[N];
int n;
void build(int v, int tl, int tr) {
  if (tl > tr) return;
  lazy[v] = 0;
  if (tl == tr) {
    mytree[v] = arr[tl] % mod;
    return;
  }
  int mid = (tl + tr) / 2;
  build(2 * v, tl, mid);
  build(2 * v + 1, mid + 1, tr);
  mytree[v] = (mytree[2 * v] + mytree[2 * v + 1]) % mod;
  mytree[v] %= mod;
}
void update(int v, int tl, int tr, int l, int r, long long int val) {
  if (tl > tr) return;
  mytree[v] += (lazy[v] * (tr - tl + 1)) % mod;
  if (tl != tr) {
    lazy[2 * v] += lazy[v] % mod;
    lazy[2 * v + 1] += lazy[v] % mod;
    lazy[2 * v] %= mod;
    lazy[2 * v + 1] %= mod;
  }
  lazy[v] = 0;
  if (tl > r || tr < l) return;
  if (tl >= l && tr <= r) {
    lazy[v] = val;
    mytree[v] += (lazy[v] * (tr - tl + 1)) % mod;
    mytree[v] %= mod;
    if (tl != tr) {
      lazy[2 * v] += lazy[v] % mod;
      lazy[2 * v + 1] += lazy[v] % mod;
      lazy[2 * v] %= mod;
      lazy[2 * v + 1] %= mod;
    }
    lazy[v] = 0;
    return;
  }
  int mid = (tl + tr) / 2;
  update(2 * v, tl, mid, l, r, val);
  update(2 * v + 1, mid + 1, tr, l, r, val);
  mytree[v] = (mytree[2 * v] + mytree[2 * v + 1]) % mod;
  mytree[v] %= mod;
}
long long int query(int v, int tl, int tr, int l, int r) {
  if (tl > tr) return 0;
  mytree[v] += (lazy[v] * (tr - tl + 1)) % mod;
  mytree[v] %= mod;
  if (tl != tr) {
    lazy[2 * v] += lazy[v] % mod;
    lazy[2 * v + 1] += lazy[v] % mod;
    lazy[2 * v] %= mod;
    lazy[2 * v + 1] %= mod;
  }
  lazy[v] = 0;
  if (tl > r || tr < l) return 0;
  if (tl >= l && tr <= r) {
    return mytree[v];
  }
  int mid = (tl + tr) / 2;
  return (query(2 * v, tl, mid, l, r) + query(2 * v + 1, mid + 1, tr, l, r)) %
         mod;
}
void solve() {
  int k;
  cin >> n >> k;
  vector<pair<int, int> > v(k);
  for (long long int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort((v).begin(), (v).end());
  for (long long int i = 0; i < n + 1; i++) {
    arr[i] = 0;
  }
  arr[0] = 1;
  arr[1] = 1;
  build(1, 1, n);
  for (int i = 1; i < n; i++) {
    for (long long int j = 0; j < k; j++) {
      arr[i] = query(1, 1, n, i, i) % mod;
      if (i + v[j].first > n) continue;
      update(1, 1, n, min(n, i + v[j].first), min(n, i + v[j].second), arr[i]);
    }
  }
  cout << query(1, 0, n - 1, n - 1, n - 1) % mod << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  int t = 0;
  while (t++ < T) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
}
