#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 2e5 + 1;
const ll inf = 1e9;
const ll mod = 998244353;
ll tree[MAX * 2];
ll l[20], r[20], n, k;
void update(ll l, ll r, ll v) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) (tree[l++] += v) %= mod;
    if (r & 1) (tree[--r] += v) %= mod;
  }
}
ll query(ll x) {
  ll ans = 0;
  x += n;
  while (x) (ans += tree[x]) %= mod, x >>= 1;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (ll i = 0; i < (ll)k; i++) cin >> l[i] >> r[i];
  update(0, 1, 1);
  for (ll i = 0; i < (ll)n; i++) {
    ll aux = query(i);
    for (ll j = 0; j < (ll)k; j++) update(i + l[j], i + r[j] + 1, aux);
  }
  cout << query(n - 1) << endl;
  return 0;
}
