#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> v(n, 0), s;
  for (int i = 0; i < (k); ++i) {
    ll l, r;
    cin >> l >> r;
    for (ll j = l; j <= r; j++) {
      s.push_back(j);
    }
  }
  sort(s.begin(), s.end());
  v[0] = 1;
  for (int i = 1; i < n; i++) {
    ll t = 0;
    for (int j = 0; j < (s.size()); ++j) {
      int x = i - s[j];
      if (x < 0) break;
      t += v[x];
    }
    v[i] = t % 998244353;
  }
  cout << v[n - 1] << endl;
  return 0;
}
