#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> lr(k);
  for (auto &v : lr) {
    ll l, r;
    cin >> l >> r;
    v = make_pair(l, r);
  }
  vector<ll> vec1(3e5, 0), vec2(3e5, 0), vec3(3e5, 0);
  vec1[1] = 1;
  vec2[1] = 1;
  vec3[1] = 1;
  for (ll i = 1; i < n; ++i) {
    for (auto &v : lr) {
      ll l = v.first;
      ll r = v.second;
      vec1[i + l] = (vec1[i + l] + vec3[i]) % mod;
      vec2[i + r] = (vec2[i + r] + vec3[i]) % mod;
    }
    vec3[i + 1] = (vec3[i] - vec2[i]) % mod;
    if (vec3[i + 1] < 0) vec3[i + 1] += mod;
    vec3[i + 1] = (vec3[i + 1] + vec1[i + 1]) % mod;
  }
  cout << vec3[n] << endl;
}
