#include <bits/stdc++.h>
using namespace std;
using ll = long long;
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;
ll mods = 998244353;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n;
  int k;
  cin >> n >> k;
  vector<ll> s(k * 2);
  ll l, r, lmin = n;
  for (ll i = 0; i < (k); i++) {
    cin >> l >> r;
    s[i * 2] = l;
    s[i * 2 + 1] = r;
    lmin = min(l, lmin);
  }
  vector<ll> tb(n + 1, 0);
  tb[1] = 1;
  for (ll i = 1; i < n - lmin; i++) {
    if (tb[i] == 0) continue;
    for (ll j = 0; j < (k); j++) {
      l = s[j * 2];
      r = s[j * 2 + 1];
      for (ll m = 0; m < (r - l + 1); m++) {
        if (i + l + m > n) break;
        tb[i + l + m] += tb[i];
        if (tb[i + l + m] > mods) tb[i + l + m] %= mods;
      }
    }
  }
  cout << tb[n] << endl;
  return 0;
}
